﻿using DGFramework;
using ETModel;
using NPOI.Util;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System.Threading.Tasks;
using DG.Tweening;
using NUnit.Framework.Internal.Execution;

namespace ETHotfix
{
    [ObjectSystem]
    public class UIHomePageComponentSystem : AwakeSystem<UIHomePageComponent>
    {
        public override void Awake(UIHomePageComponent self)
        {
            Log.Debug("UIHomePageComponent登录初始化====");
            self.Awake();
        }
    }
   [UIComponent(UIType.UIHomePage)]
    public class UIHomePageComponent : Component
    {
        //主页
        #region
        public long GamePlayGoid;//自己的金币数量
        public int GamePlayXingxing;//自己的星星数量
        public int GamePlayHudun;//自己的护盾数量
        public int GamePlayNengliang;//自己的能量数量
        private Text Txt_name;//敌人名字
        public Text Txt_Xingxing;//星星数量
        private Text Txt_Goid;//金币
        private Text Txt_Gdhongdian;//设置红点数量
        private Text Txt_Daojishi;//能量恢复倒计时
        private Text Txt_DIrengoid;//敌人的金币
        private Text Txt_Cwhongdian;//宠物红点数量
        private Text Txt_Huode;//自己单局获得金币
        private Text Txt_nengliang;//多出的能量点数
        private Text Txt_NengliangTxt;

        private GameObject Obj_daojishiobj;
        private GameObject ShezhiHongdian;//设置红点显示
        private GameObject ChongwuHongdian;//宠物红点显示
        private GameObject Obj_hudun;//自己护盾
        private GameObject Mask;
        private GameObject Obj_xianGameObject;
        private GameObject Toushang;
        private GameObject Obj_Texiao;
        private GameObject Obj_Attack;
        private GameObject Obj_Touqu;
        private GameObject Obj_Guochang;
        private GameObject Obj_Attackling;
        private GameObject ChouJiang_zhuanpan_tx;
        private GameObject ChouJiang_dianji_tx;
        private Image Img_touxiang;//敌人头像
        private Image Img_Jindutiao;//自己次数

        private Button Btn_zhuye;//拉霸开始按钮
        private Button Btn_zhadan;//复仇
        private Button Btn_kapai;//卡牌页面
        private Button Btn_gengduo;//设置界面
        private Button Btn_fangzi;//商店
        private Button Btn_fanbei;//翻倍按钮
        private Button Btn_chuizi;//点击建筑
        private Button Btn_chongwu;//点击宠物按钮
        private Button Btn_AddGoid;//购买金币
        private Button Btn_laba;//拉霸界面
        private List<GameObject> xianlist = new List<GameObject>();

        //转动
        public Sprite[] ImgIcon;
        public Sprite[] BlurredPicture;
        public Transform[][] Icons;
        public Dictionary<int, Vector3> DicIconVector;
        public int[] ArrIconStatus = new int[5];//状态：0结束；1开始滚动；2剩下最后一圈；3倒滚；
        public int[] iArrRollCnt = new int[5];//第一次结束后滚动圈数
        public int[][] ArrIconsResult = new int[3][];
        private bool Runbool = false;

        private Sprite sdda;
        private Sprite sd;
        private Sprite kpda;
        private Sprite kp;
        private Sprite zhuye;
        private Sprite strarrun;
        private Sprite ctda;
        private Sprite ct;
        private Sprite crda;
        private Sprite cr;
        private Action _function;
     
        #region 攻击和偷取界面
        private GameObject Obj_Touquover;
        private GameObject Obj_TouquInfoback;
        private GameObject Obj_attackover;
        private GameObject Obj_AttackInfoback;
        private GameObject jianzhu_paoche_tx;
        private GameObject Obj_Attacfuchouliebiao;
        private GameObject Obj_Attackfuchou;

        private Button Btn_TouquOver;
        private Button Btn_Touqufx;
        private Button Btn_attackOver;
        private Button Btn_attackfx;
        private Button Btn_FRIENDS;
        private Button Btn_REVENGE;

        private Text Txt_touquoverms;
        private Text Txt_Touqunumber;
        private Text Txt_Touqugoid;
        private Text Txt_Touqums;
        private Text Txt_Touquname;
        private Text Txt_attackoverms;
        private Text Txt_attackms;
        private Text Txt_attackname;
        private Text Txt_touqutishi;

        private Image Ima_Touqutx;
        private Image Ima_attacktx;

        private Animator Attackanimator;
        #endregion

        #endregion

        #region//更多选项

        #region//更多选项进入页面
        private GameObject Obj_More;
        private GameObject Obj_Morebtn;


        private Button Btn_ExitMore;
        private Button Btn_Morebangding;

        private Image Image_moretouxiang;

        private Text Txt_MoreName;
        #endregion

        #region//排行榜
        private GameObject Obj_RankingBack;
        private GameObject Obj_ScrollView;

        private Button Btn_haoyouRanking;
        private Button Btn_shijieRanking;
        private Button Btn_bendiRanking;
        private Button Btn_ExitRanking;

        #endregion

        #region//邀请召回
        private GameObject Obj_InvitationRecallBack;
        private Button Btn_ExitInvitationRecall;
        private Button Btn_Invitation;
        private Button Btn_recall;


        #endregion

        #region//VIP
        private GameObject Obj_VipTc;
        private Button Btn_ExitViptc;

        private Button Btn_VIpMonth;
        private Button Btn_VipWeek;
        #endregion

        #region//地图

        #endregion

        #region//消息
        private GameObject Obj_MessageBack;
        private Button Btn_ExitMessage;
        private GameObject Obj_Scrollhuadong;
        #endregion


        #region//设置
        private GameObject Obj_SettingBack;

        private Button Btn_setyinxiao;
        private Button Btn_setyinyue;
        private Button Btn_setzhengdong;
        private Button Btn_setliaotian;
        private Button Btn_setvip;
        private Button Btn_settongzhi;
        private Button Btn_setkefu;
        private Button Btn_ExiteSeting;

        #endregion


        #region//好友
        private GameObject Obj_FriendlBack;
        private Button Btn_ExitFriendl;
        private Button Btn_InviteFriends;
        #endregion

        #region//修改个人信息
        public GameObject Obj_AmendinfoBack;
        private Button Btn_ExitAmendinfo;
        #endregion

        private GameObject Fuchou_Panel;
        private Button Exit_fuchoubang;
        #endregion


        #region//关卡
        private Image Img_Shangsheng;


        private Button Btn_Xiajiang;
        private Button Btn_Guanka;
        private Button Btn_ExieGuankaditu;
        //private Button Btn_Shengjijz;

        private GameObject Obj_jianzhu;
        private GameObject Obj_Jianchao;
        private GameObject Obj_GuankaDitu;
        private GameObject Obj_zhangshiditu;
        private GameObject jianzhu_wancheng_star02_tx;
        private GameObject Obj_xingxing;
        private GameObject Obj_DIbubtn;
        private GameObject ScrollView;
        private GameObject Obj_ScrollDitu;
        private Button Btn_zhangshiditu;
        private Text Txt_MapsName;

        private Material Gkfei;
        #endregion

        #region//复仇
        private GameObject Obj_fuchouliebiao;
        #endregion

        #region//卡牌
        private GameObject Obj_Kaipaijiesuo;
        private List<Transform> kapaiguankalist = new List<Transform>();
        private GameObject Kapianobj;
        private Button Btn_exitkapian;
        private Text Txt_tishiguanka;
        private GameObject Obj_Tanchuang;
        private GameObject Obj_Kapaitishi;
        private Button Btn_tuichutishi;
        private Button Btn_kapaibangzu;
        private Button Btn_kapaitishi;
        private Button Btn_Kapaishop;
        private GameObject Obj_kapaimiaosu;

        private Button Btn_Exitkapaimiaosu;
        private Button Btn_kapaizengsong;
        private Text Txt_kapaimiaosu;
        private Image Ima_kapaimisu;
        #endregion

        #region//商店
        private GameObject Obj_Vip;
        private GameObject Obj_Tilishiwu;
        private GameObject Obj_Jinbi;
        private GameObject Obj_Nengliang;
        private GameObject Obj_kapaiBox;
        private GameObject Obj_watchBox;
        #endregion

        #region//宠物
        private GameObject Obj_ChongwuObj;
        private GameObject Obj_CwTanchuang;
        private GameObject Obj_chongwuhelp;
        private GameObject Obj_chongwuMask;
        private GameObject Obj_chizi;

        private Text Txt_miaosu;
        private Text Txt_molizhi;
        private Text Txt_miaosu1;
        private Text Txt_miaosu2;
        private Text Txt_Jinyan;
        private Text Txt_twlv;
        private Text Txt_chongwuname;
        private Text Txt_cwnengliangtxt;
        private Text Txt_cwzyshiwutxt;
        private Text Txt_cwzynengliangtxt;
        private Text Txt_cwshengjitxt;

        private Image Img_dianwan;
        private Image Ima_diantwo;
        private Image Img_amount;

        private Button Btn_exitchongwu;
        private Button Btn_chongwuhelp;
        private Button Btn_mianfei;
        private Button Btn_huifunengliang;
        private Button Btn_shengji;
        private Button Btn_Exitcwtc;
        private Button Btn_ExitcwHelp;

        #endregion


        ReferenceCollector rc;
        ReferenceCollector KapaiSpr;
        ReferenceCollector Gengduo;
        ReferenceCollector ShopSpr;
        ReferenceCollector ChongwuSpr;
        ReferenceCollector GuankaSpr;
        ReferenceCollector SoundSpr;
        public void Awake()
        {
          

            rc = this.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
            KapaiSpr= this.GetParent<UI>().GameObject.transform.Find("KapaiSpr").GetComponent<ReferenceCollector>();
            Gengduo = this.GetParent<UI>().GameObject.transform.Find("GengduoSpr").GetComponent<ReferenceCollector>();
            ShopSpr = this.GetParent<UI>().GameObject.transform.Find("ShopSpr").GetComponent<ReferenceCollector>();
            ChongwuSpr = this.GetParent<UI>().GameObject.transform.Find("ChongwuSpr").GetComponent<ReferenceCollector>();
            GuankaSpr = this.GetParent<UI>().GameObject.transform.Find("GuankaSpr").GetComponent<ReferenceCollector>();
            SoundSpr = this.GetParent<UI>().GameObject.transform.Find("SoundSpr").GetComponent<ReferenceCollector>();
            //主页
            #region
            ScrollView = rc.Get<GameObject>("ScrollView");
            ScrollView.transform.Find("Viewport/Content").GetComponent<GridLayoutGroup>().cellSize = new Vector2(this.GetParent<UI>().GameObject.GetComponent<RectTransform>().rect.width, this.GetParent<UI>().GameObject.GetComponent<RectTransform>().rect.height);
            Txt_name = rc.Get<GameObject>("Txt_name").GetComponent<Text>();
            Txt_Xingxing = rc.Get<GameObject>("Txt_Xingxing").GetComponent<Text>();
            Txt_Goid = rc.Get<GameObject>("Txt_Goid").GetComponent<Text>();
            Txt_Gdhongdian = rc.Get<GameObject>("Txt_Gdhongdian").GetComponent<Text>();
            Txt_Daojishi = rc.Get<GameObject>("Txt_Daojishi").GetComponent<Text>();
            Txt_DIrengoid = rc.Get<GameObject>("Txt_DIrengoid").GetComponent<Text>();
            Txt_Cwhongdian = rc.Get<GameObject>("Txt_Cwhongdian").GetComponent<Text>();
            Txt_nengliang = rc.Get<GameObject>("Txt_nengliang").GetComponent<Text>();
            Txt_Huode = rc.Get<GameObject>("Txt_Huode").GetComponent<Text>();
            Txt_NengliangTxt = rc.Get<GameObject>("Txt_NengliangTxt").GetComponent<Text>();
            sdda  = rc.Get<Sprite>("sdda");
            sd = rc.Get<Sprite>("sd");
            kpda = rc.Get<Sprite>("kpda");
            kp = rc.Get<Sprite>("kp");
            zhuye = rc.Get<Sprite>("zhuye");
            strarrun = rc.Get<Sprite>("strarrun");
            ctda = rc.Get<Sprite>("ctda");
            ct = rc.Get<Sprite>("ct");
            crda = rc.Get<Sprite>("crda");
            cr = rc.Get<Sprite>("cr");

            ImgIcon = new Sprite[10];
            BlurredPicture = new Sprite[10];
            for (int i = 0; i < 6; i++)
            {
                ImgIcon[i] = rc.Get<Sprite>("SGJ_icon_"+i);
            }
            for (int i = 0; i < 6; i++)
            {
                BlurredPicture[i] = rc.Get<Sprite>("SGJ_icon_5" + i);
            }
            ShezhiHongdian = rc.Get<GameObject>("ShezhiHongdian");
            Obj_daojishiobj = rc.Get<GameObject>("Obj_daojishiobj");
            ChongwuHongdian = rc.Get<GameObject>("ChongwuHongdian");
            Obj_hudun = rc.Get<GameObject>("Obj_hudun");
            Mask = rc.Get<GameObject>("Mask");
            Toushang = rc.Get<GameObject>("Toushang");
            Obj_Texiao = rc.Get<GameObject>("Obj_Texiao");
            Obj_xianGameObject = rc.Get<GameObject>("Obj_xianGameObject");
            Obj_Attack = rc.Get<GameObject>("Obj_Attack");
            Obj_Attackling = rc.Get<GameObject>("Obj_Attackling");
            ChouJiang_zhuanpan_tx = rc.Get<GameObject>("ChouJiang_zhuanpan_tx");
            ChouJiang_dianji_tx = rc.Get<GameObject>("ChouJiang_dianji_tx");
            Obj_Attackling.transform.GetChild(2).GetComponent<Button>().onClick.Add(() => { Startatt(0); });
            for (int i = 0; i < 5; i++)
            {
                    int prnumber = i;
                    Obj_Attack.transform.Find("_" + (i + 1)).GetChild(1).GetComponent<Button>().onClick.Add(() => { Startatt(prnumber); });
            }
            Obj_Touqu = rc.Get<GameObject>("Obj_Touqu");
            Obj_Guochang = rc.Get<GameObject>("Obj_Guochang");
            for (int i = 0; i < 5; i++)
            {
                xianlist.Add(Obj_xianGameObject.transform.GetChild(i).gameObject);
            }

            Img_touxiang = rc.Get<GameObject>("Img_touxiang").GetComponent<Image>();
            Img_Jindutiao = rc.Get<GameObject>("Img_Jindutiao").GetComponent<Image>();

            Btn_zhuye = rc.Get<GameObject>("Btn_zhuye").GetComponent<Button>();
           // Btn_zhuye.onClick.Add(StartButton);//启动

           Btn_zhadan = rc.Get<GameObject>("Btn_zhadan").GetComponent<Button>();
            Btn_zhadan.onClick.Add(Tiaozhuan5);//复仇

            Btn_kapai = rc.Get<GameObject>("Btn_kapai").GetComponent<Button>();
            Btn_kapai.onClick.Add(Tiaozhuan2);//卡片

            Btn_gengduo = rc.Get<GameObject>("Btn_gengduo").GetComponent<Button>();
            Btn_gengduo.onClick.Add(OnBtnRUnMore);//设置

            Btn_fangzi = rc.Get<GameObject>("Btn_fangzi").GetComponent<Button>();
            Btn_fangzi.onClick.Add(Tiaozhuan1);//商店

            Btn_fanbei = rc.Get<GameObject>("Btn_fanbei").GetComponent<Button>();
            Btn_fanbei.onClick.Add(OnBtnfanbei);//翻倍

            Btn_chuizi = rc.Get<GameObject>("Btn_chuizi").GetComponent<Button>();
            Btn_chuizi.onClick.Add(Tiaozhuan4);//建筑

            Btn_chongwu = rc.Get<GameObject>("Btn_chongwu").GetComponent<Button>();
            Btn_chongwu.onClick.Add(Cptinfo);//宠物

            Btn_AddGoid = rc.Get<GameObject>("Btn_AddGoid").GetComponent<Button>();
            Btn_AddGoid.onClick.Add(Tiaozhuan1); //购买金币

            Btn_laba = rc.Get<GameObject>("Btn_laba").GetComponent<Button>();
            Btn_laba.onClick.Add(Tiaozhuan3); //
            Icons = new Transform[3][];
            for (int i = 0; i < 3; i++)
            {
                Icons[i] = new Transform[5];
                for (int j = 0; j < 5; j++)
                {
                    Icons[i][j] = Mask.transform.Find((i + 1) + "/" + (j+1));
                }
            }

            SetMoveVector();
            Log.Debug("开始获取信息");
        


            
            #endregion;


            #region 攻击和偷取界面
            Obj_Touquover = rc.Get<GameObject>("Obj_Touquover");
            Obj_TouquInfoback = rc.Get<GameObject>("Obj_TouquInfoback");
            Obj_attackover = rc.Get<GameObject>("Obj_attackover");
            Obj_AttackInfoback = rc.Get<GameObject>("Obj_AttackInfoback");
            Obj_Attacfuchouliebiao = Gengduo.Get<GameObject>("Obj_Attacfuchouliebiao");
            Obj_Attackfuchou = Gengduo.Get<GameObject>("Obj_Attackfuchou");

            Btn_TouquOver = rc.Get<GameObject>("Btn_TouquOver").GetComponent<Button>();
            Btn_TouquOver.onClick.Add(TouquOver);//偷取结束

            Btn_Touqufx = rc.Get<GameObject>("Btn_Touqufx").GetComponent<Button>();
            Btn_Touqufx.onClick.Add(TouquOver);//偷取绑定

            Btn_attackfx = rc.Get<GameObject>("Btn_attackfx").GetComponent<Button>();
            Btn_attackfx.onClick.Add(AttackOver);//攻击绑定

            Btn_attackOver = rc.Get<GameObject>("Btn_attackOver").GetComponent<Button>();
            Btn_attackOver.onClick.Add(AttackOver);//攻击结束

            Btn_FRIENDS = rc.Get<GameObject>("Btn_FRIENDS").GetComponent<Button>();
            Btn_FRIENDS.onClick.Add(ToRun);//

            Btn_REVENGE = rc.Get<GameObject>("Btn_REVENGE").GetComponent<Button>();
            Btn_REVENGE.onClick.Add(OnAttackItem);//复仇

            Txt_touquoverms = rc.Get<GameObject>("Txt_touquoverms").GetComponent<Text>();
            Txt_Touqunumber = rc.Get<GameObject>("Txt_Touqunumber").GetComponent<Text>();
            Txt_Touqugoid = rc.Get<GameObject>("Txt_Touqugoid").GetComponent<Text>();
            Txt_Touqums = rc.Get<GameObject>("Txt_Touqums").GetComponent<Text>();
            Txt_Touquname = rc.Get<GameObject>("Txt_Touquname").GetComponent<Text>();
            Txt_attackoverms = rc.Get<GameObject>("Txt_attackoverms").GetComponent<Text>();
            Txt_attackms = rc.Get<GameObject>("Txt_attackms").GetComponent<Text>();
            Txt_attackname = rc.Get<GameObject>("Txt_attackname").GetComponent<Text>();
            Txt_touqutishi = rc.Get<GameObject>("Txt_touqutishi").GetComponent<Text>();

            Ima_Touqutx = rc.Get<GameObject>("Ima_Touqutx").GetComponent<Image>();
            Ima_attacktx = rc.Get<GameObject>("Ima_attacktx").GetComponent<Image>();
            jianzhu_paoche_tx = rc.Get<GameObject>("jianzhu_paoche_tx");
            Attackanimator = jianzhu_paoche_tx.transform.GetComponent<Animator>();
            Attackanimator.SetBool("Attackbool", false);
            for (int i = 0; i < 4; i++)
            {
                int prints = i;
                Obj_Touqu.transform.Find("Tou" + i).GetComponent<Button>().onClick.Add(() => { Starttq(prints); });
            }
           
            #endregion


            #region//更多选项

            #region//更多选项进入页面
            Obj_More = rc.Get<GameObject>("Obj_More");
            Obj_Morebtn = rc.Get<GameObject>("Obj_Morebtn");
            for (int i = 0; i < 8; i++)
            {
                int prnumber = i;
                Obj_Morebtn.transform.GetChild(i).GetComponent<Button>().onClick.Add(() => { OnRunyemian(prnumber); });

            }
            Btn_ExitMore = rc.Get<GameObject>("Btn_ExitMore").GetComponent<Button>();
            Btn_ExitMore.onClick.Add(OnBtnExitMore);
            Btn_Morebangding = rc.Get<GameObject>("Btn_Morebangding").GetComponent<Button>();
            Btn_Morebangding.onClick.Add(OnBtnMorebangding);

            Txt_MoreName = rc.Get<GameObject>("Txt_MoreName").GetComponent<Text>();

            Image_moretouxiang= rc.Get<GameObject>("Image_moretouxiang").GetComponent<Image>();

            Image_moretouxiang.GetComponent<Button>().onClick.Add(AmendInfo);

            Fuchou_Panel = Gengduo.Get<GameObject>("Fuchou_Panel");
            Exit_fuchoubang = Gengduo.Get<GameObject>("Exit_fuchoubang").GetComponent<Button>();
            Exit_fuchoubang.onClick.Add(OnExitfuchoubang);
            #endregion


            #region//排行榜
            Obj_RankingBack = rc.Get<GameObject>("Obj_RankingBack");
            Btn_haoyouRanking = rc.Get<GameObject>("Btn_haoyouRanking").GetComponent<Button>();
            Btn_haoyouRanking.onClick.Add(OnBtnhaoyouRanking);
            Btn_shijieRanking = rc.Get<GameObject>("Btn_shijieRanking").GetComponent<Button>();
            Btn_shijieRanking.onClick.Add(OnBtn_hijieRanking);
            Btn_bendiRanking = rc.Get<GameObject>("Btn_bendiRanking").GetComponent<Button>();
            Btn_bendiRanking.onClick.Add(OnBtnbendiRanking);
            Btn_ExitRanking = rc.Get<GameObject>("Btn_ExitRanking").GetComponent<Button>();
            Btn_ExitRanking.onClick.Add(OnBtnExitRanking);
            Obj_ScrollView = Gengduo.Get<GameObject>("Obj_ScrollView");
            #endregion


            #region//邀请召回
            Obj_InvitationRecallBack = rc.Get<GameObject>("Obj_InvitationRecallBack");

            Btn_ExitInvitationRecall = rc.Get<GameObject>("Btn_ExitInvitationRecall").GetComponent<Button>();
            Btn_ExitInvitationRecall.onClick.Add(OnBtnExitInvitationRecall);
            Btn_Invitation = rc.Get<GameObject>("Btn_Invitation").GetComponent<Button>();
            Btn_Invitation.onClick.Add(OnBtnInvitation);
            Btn_recall = rc.Get<GameObject>("Btn_recall").GetComponent<Button>();
            Btn_recall.onClick.Add(OnBtnrecall);

            #endregion

            #region//VIP
            Obj_VipTc = Gengduo.Get<GameObject>("Obj_VipTc");
            Btn_ExitViptc = Gengduo.Get<GameObject>("Btn_ExitViptc").GetComponent<Button>();
            Btn_ExitViptc.onClick.Add(OnBtnExitViptc);

            Btn_VIpMonth = Gengduo.Get<GameObject>("Btn_VIpMonth").GetComponent<Button>();
            Btn_VIpMonth.onClick.Add(OnBtnVIpMonth);

            Btn_VipWeek = Gengduo.Get<GameObject>("Btn_VipWeek").GetComponent<Button>();
            Btn_VipWeek.onClick.Add(OnBtnVipWeek);

            #endregion

            #region//地图


            #endregion

            #region//消息
            Obj_MessageBack = rc.Get<GameObject>("Obj_MessageBack");
            Btn_ExitMessage = rc.Get<GameObject>("Btn_ExitMessage").GetComponent<Button>();
            Btn_ExitMessage.onClick.Add(OnBtnExitMessage);
            Obj_Scrollhuadong = Gengduo.Get<GameObject>("Obj_Scrollhuadong");
            #endregion


            #region//设置
            Obj_SettingBack = rc.Get<GameObject>("Obj_SettingBack");

            Btn_setyinxiao = rc.Get<GameObject>("Btn_setyinxiao").GetComponent<Button>();
            Btn_setyinxiao.onClick.Add(OnBtnsetyinxiao);

            Btn_setyinyue = rc.Get<GameObject>("Btn_setyinyue").GetComponent<Button>();
            Btn_setyinyue.onClick.Add(OnBtnsetyinyue);

            Btn_setzhengdong = rc.Get<GameObject>("Btn_setzhengdong").GetComponent<Button>();
            Btn_setzhengdong.onClick.Add(OnBtnsetzhengdong);


            Btn_settongzhi = rc.Get<GameObject>("Btn_settongzhi").GetComponent<Button>();
            Btn_settongzhi.onClick.Add(OnBtnsettongzhi);

            Btn_ExiteSeting = rc.Get<GameObject>("Btn_ExiteSeting").GetComponent<Button>();
            Btn_ExiteSeting.onClick.Add(OnBtnExiteSeting);

            #endregion


            #region//好友
            Obj_FriendlBack = rc.Get<GameObject>("Obj_FriendlBack");

            Btn_ExitFriendl = rc.Get<GameObject>("Btn_ExitFriendl").GetComponent<Button>();
            Btn_ExitFriendl.onClick.Add(OnBtnExitFriendl);
            Btn_InviteFriends = rc.Get<GameObject>("Btn_InviteFriends").GetComponent<Button>();
            Btn_InviteFriends.onClick.Add(OnBtnInviteFriends);
            #endregion

            #region//修改个人信息
            Obj_AmendinfoBack = Gengduo.Get<GameObject>("Obj_AmendinfoBack");
            Btn_ExitAmendinfo = Gengduo.Get<GameObject>("Btn_ExitAmendinfo").GetComponent<Button>();
            Btn_ExitAmendinfo.onClick.Add(OnBtnExitAmendinfo);

            #endregion

            #region//音效
            AudioManagerP._instance.audioList.Clear();
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Ditu_wanchengyingyue"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Ditu_wanchengyanhuo"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Ditu_wancheng1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Tanchui_tanchuangqipao_shanxian"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Tanchui_tanchuangqipao4"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Tanchui_tanchuangqipao3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Tanchui_tanchuangqipao2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Tanchui_tanchuangqipao1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("xingxingshengji"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("zhuandong_yisheng"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("zhuandong_chixu2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("zhuandong_chixu1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("kapai_shouji3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("kapai_shouji2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("kapai_shouji1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Jirsuo_tiaodaoxiageditu2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Jirsuo_tiaodaoxiageditu1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("xiujianwancheng2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("xiujianwancheng1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("zhunbeitouxi_touxiao2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("zhunbeitouxi_touxiao1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Touxizhong_touxishibai5"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Touxizhong_touxishibai4"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Touxizhong_touxishibai3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Touxizhong_touxishibai2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Touxizhong_touxishibai1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("TouxiChenggong_huodeyidian"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("TouxiChenggong_huodequanbu"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Tishi_beitouxi"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Jinbi_yinxiao"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Jinbi_sanluo3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Jinbi_sanluo2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Jinbi_sanluo1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_paotanfashe"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_paodanluoxia"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_paodanbaozha2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_paodanbaozha1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_dazhong"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_Daidianfashe"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Gongji_chenggongcuihui"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Chouzhong_gongji_diandai"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("nengliang_huirunengliangkuang3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("nengliang_huirunengliangkuang2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("nengliang_huirunengliangkuang1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("nengliang_chouzhonghuiru3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("nengliang_chouzhonghuiru2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("nengliang_chouzhonghuiru1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Dunpaidangzhugongji"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Chouzhong_dunpai"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("TouxiBgm"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("GongjiBGM2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("GongjiBGM1"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("GjTxBGM2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("GjTxBGM"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("BGM4"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("BGM3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("BGM2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Anjian_3"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Anjian_2"));
            AudioManagerP._instance.audioList.Add(SoundSpr.Get<AudioClip>("Anjian_1"));
            AudioManagerP._instance.Leibiaoaddclip();

            #endregion
            #endregion


            #region//关卡
            Btn_Xiajiang = rc.Get<GameObject>("Btn_Xiajiang").GetComponent<Button>();
            Btn_Xiajiang.onClick.Add(OnBtnXiajiang);//启动

            Btn_Guanka = rc.Get<GameObject>("Btn_Guanka").GetComponent<Button>();
            Btn_Guanka.onClick.Add(OnBtnGuanka);

            Btn_ExieGuankaditu = rc.Get<GameObject>("Btn_ExieGuankaditu").GetComponent<Button>();
            Btn_ExieGuankaditu.onClick.Add(OnBtnExitGuanka);

            //Btn_Shengjijz= rc.Get<GameObject>("Btn_Shengjijz").GetComponent<Button>();
            //Btn_Shengjijz.onClick.Add(OnBtnShengjijz);


            Btn_zhangshiditu = GuankaSpr.Get<GameObject>("Btn_zhangshiditu").GetComponent<Button>();
            Btn_zhangshiditu.onClick.Add(ExirXianshiditu);
            Obj_jianzhu = rc.Get<GameObject>("Obj_jianzhu");
            Obj_Jianchao = rc.Get<GameObject>("Obj_Jianchao");
            Obj_GuankaDitu = rc.Get<GameObject>("Obj_GuankaDitu");
            Obj_zhangshiditu = GuankaSpr.Get<GameObject>("Obj_zhangshiditu");
            jianzhu_wancheng_star02_tx = rc.Get<GameObject>("jianzhu_wancheng_star02_tx");
            Obj_xingxing = rc.Get<GameObject>("Obj_xingxing");
            Obj_DIbubtn = rc.Get<GameObject>("Obj_DIbubtn");
            Obj_ScrollDitu = rc.Get<GameObject>("Obj_ScrollDitu");

            Gkfei = rc.Get<Material>("Gkfei");
            Img_Shangsheng = rc.Get<GameObject>("Img_Shangsheng").GetComponent<Image>();


            Txt_MapsName = rc.Get<GameObject>("Txt_MapsName").GetComponent<Text>();

            for (int i = 0; i < 5; i++)
            {
                int numbers = i;
                // Obj_jianzhu.transform.GetChild(i).Find("Btn_shengji").GetComponent<Button>().onClick.Add(() => { Startaupguanka(numbers); });
                Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().onClick.Add(() => { Startaupguanka(numbers); });
            }

        
            #endregion

            #region//复仇
            Obj_fuchouliebiao = rc.Get<GameObject>("Obj_fuchouliebiao");
       
  
            #endregion

            #region//卡牌
            Obj_Kaipaijiesuo = KapaiSpr.Get<GameObject>("Obj_Kaipaijiesuo");
            for (int i = 0; i < Obj_Kaipaijiesuo.transform.childCount; i++)
            {
                var child = Obj_Kaipaijiesuo.transform.GetChild(i);
                kapaiguankalist.Add(child);
            }
            Kapianobj = KapaiSpr.Get<GameObject>("Kapianobj");
            for (int i = 0; i < kapaiguankalist.Count; i++)
            {
                int pirnt = i;
                kapaiguankalist[i].GetComponent<Button>().onClick.Add(() => { SetOnkapai(pirnt); });
            }
            Btn_exitkapian = KapaiSpr.Get<GameObject>("Btn_exitkapian").GetComponent<Button>();
            Btn_exitkapian.onClick.Add(OnBtnexitkapian);//地图

            Txt_tishiguanka = KapaiSpr.Get<GameObject>("Txt_tishiguanka").GetComponent<Text>();

            Obj_Tanchuang = KapaiSpr.Get<GameObject>("Obj_Tanchuang");
            Obj_Kapaitishi = KapaiSpr.Get<GameObject>("Obj_Kapaitishi");

            Btn_tuichutishi = KapaiSpr.Get<GameObject>("Btn_tuichutishi").GetComponent<Button>();
            Btn_tuichutishi.onClick.Add(OnBtntuichutishi);//提示

            Btn_kapaibangzu = KapaiSpr.Get<GameObject>("Btn_kapaibangzu").GetComponent<Button>();
            Btn_kapaibangzu.onClick.Add(OnBtnkapaibangzu);
            Btn_kapaitishi = KapaiSpr.Get<GameObject>("Btn_kapaitishi").GetComponent<Button>();
            Btn_kapaitishi.onClick.Add(OnBtnkapaitishi);
            Btn_Kapaishop = KapaiSpr.Get<GameObject>("Btn_Kapaishop").GetComponent<Button>();
            Btn_Kapaishop.onClick.Add(Tiaozhuan1);

            Obj_kapaimiaosu = KapaiSpr.Get<GameObject>("Obj_kapaimiaosu");

            Btn_Exitkapaimiaosu = KapaiSpr.Get<GameObject>("Btn_Exitkapaimiaosu").GetComponent<Button>();
            Btn_Exitkapaimiaosu.onClick.Add(OnBtnExitkapaimiaosu);
            Btn_kapaizengsong = KapaiSpr.Get<GameObject>("Btn_kapaizengsong").GetComponent<Button>();
            Btn_kapaizengsong.onClick.Add(OnBtnkapaizengsong);

            Txt_kapaimiaosu = KapaiSpr.Get<GameObject>("Txt_kapaimiaosu").GetComponent<Text>();
            Ima_kapaimisu = KapaiSpr.Get<GameObject>("Ima_kapaimisu").GetComponent<Image>();
            #endregion

            #region//商店
            Obj_Vip = ShopSpr.Get<GameObject>("Obj_Vip");
            Obj_Tilishiwu = ShopSpr.Get<GameObject>("Obj_Tilishiwu");
            Obj_Jinbi = ShopSpr.Get<GameObject>("Obj_Jinbi");
            Obj_Nengliang = ShopSpr.Get<GameObject>("Obj_Nengliang");
            Obj_kapaiBox = ShopSpr.Get<GameObject>("Obj_kapaiBox");
            Obj_watchBox = ShopSpr.Get<GameObject>("Obj_watchBox");

            #endregion

            #region//宠物
            Obj_ChongwuObj = ChongwuSpr.Get<GameObject>("Obj_ChongwuObj");
            Obj_CwTanchuang = ChongwuSpr.Get<GameObject>("Obj_CwTanchuang");
            Obj_chongwuhelp = ChongwuSpr.Get<GameObject>("Obj_chongwuhelp");
            Obj_chongwuMask = ChongwuSpr.Get<GameObject>("Obj_chongwuMask");
            Obj_chizi = ChongwuSpr.Get<GameObject>("Obj_chizi");

            Btn_Exitcwtc = ChongwuSpr.Get<GameObject>("Btn_Exitcwtc").GetComponent<Button>();
            Btn_Exitcwtc.onClick.Add(OnBtnExitcwtc);
            Btn_shengji = ChongwuSpr.Get<GameObject>("Btn_shengji").GetComponent<Button>();
            Btn_shengji.onClick.Add(OnBtnshengji);
            Btn_huifunengliang = ChongwuSpr.Get<GameObject>("Btn_huifunengliang").GetComponent<Button>();
            Btn_huifunengliang.onClick.Add(OnBtnhuifunengliang);
            Btn_mianfei = ChongwuSpr.Get<GameObject>("Btn_mianfei").GetComponent<Button>();
            Btn_mianfei.onClick.Add(OnBtnmianfei);
            Btn_chongwuhelp = ChongwuSpr.Get<GameObject>("Btn_chongwuhelp").GetComponent<Button>();
            Btn_chongwuhelp.onClick.Add(OnBtnchongwuhelp);
            Btn_exitchongwu = ChongwuSpr.Get<GameObject>("Btn_exitchongwu").GetComponent<Button>();
            Btn_exitchongwu.onClick.Add(OnBtnexitchongwu);
            Btn_ExitcwHelp = ChongwuSpr.Get<GameObject>("Btn_ExitcwHelp").GetComponent<Button>();
            Btn_ExitcwHelp.onClick.Add(OnBtnExitcwHelp); 

             Txt_miaosu = ChongwuSpr.Get<GameObject>("Txt_miaosu").GetComponent<Text>();
            Txt_molizhi = ChongwuSpr.Get<GameObject>("Txt_molizhi").GetComponent<Text>();
            Txt_miaosu1 = ChongwuSpr.Get<GameObject>("Txt_miaosu1").GetComponent<Text>();
            Txt_miaosu2 = ChongwuSpr.Get<GameObject>("Txt_miaosu2").GetComponent<Text>();
            Txt_Jinyan = ChongwuSpr.Get<GameObject>("Txt_Jinyan").GetComponent<Text>();
            Txt_twlv = ChongwuSpr.Get<GameObject>("Txt_twlv").GetComponent<Text>();
            Txt_chongwuname = ChongwuSpr.Get<GameObject>("Txt_chongwuname").GetComponent<Text>();
            Txt_cwzyshiwutxt = ChongwuSpr.Get<GameObject>("Txt_cwzyshiwutxt").GetComponent<Text>();
            Txt_cwzynengliangtxt = ChongwuSpr.Get<GameObject>("Txt_cwzynengliangtxt").GetComponent<Text>();
            Txt_cwnengliangtxt = ChongwuSpr.Get<GameObject>("Txt_cwnengliangtxt").GetComponent<Text>();
            Txt_cwshengjitxt = ChongwuSpr.Get<GameObject>("Txt_cwshengjitxt").GetComponent<Text>();

            Img_dianwan = ChongwuSpr.Get<GameObject>("Img_dianwan").GetComponent<Image>();
            Ima_diantwo = ChongwuSpr.Get<GameObject>("Ima_diantwo").GetComponent<Image>();
            Img_amount = ChongwuSpr.Get<GameObject>("Img_amount").GetComponent<Image>();

            for (int i = 0; i < Obj_chongwuMask.transform.childCount; i++)//获取物体下子物体数量
            {
                int numbers = i;
                Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Img_chongwu").GetComponent<Button>().onClick.Add(() => { OnsetCwtc(numbers); });
            }


        #endregion
             SetPlayinfo().Coroutine();
            GetMaps().Coroutine();
            GetFuchou().Coroutine();
           // GetKapai().Coroutine();
           GetShopinfo().Coroutine();
            ScrollViewMoreSlide.Instance.SlCallBack = OnSlCallBack;

        }

    








        #region //主页

        private void Onstartbutton(string bo) 
        {
            if (bo=="true")
            {
                if (Runbool)
                {
                    Runbool = false;//取消自动
                    Btn_zhuye.GetComponent<Image>().sprite = rc.Get<Sprite>("strarrun");
                }
                else
                {
                    Runbool = true;//设置自动
                    Btn_zhuye.GetComponent<Image>().sprite = rc.Get<Sprite>("ZidongStart");
                    StartButton();
                }
            }
            else
            {
                if (Runbool)
                {
                    Runbool = false;//取消自动
                    Btn_zhuye.GetComponent<Image>().sprite = rc.Get<Sprite>("strarrun");
                }
                else
                {
                    StartButton();
                }
            }
        
        }

        private void StartButton() 
        {
            Log.Debug("点击启动的时候" + Startrunbool);
            if (!Startrunbool&& GamePlayNengliang-(Fanbeinumberlist[FanbeiInt])>=0)
            {
                OnStartLaba().Coroutine();
                StartRoll(RollStop);

                EnergySet(GamePlayNengliang - (Fanbeinumberlist[FanbeiInt]));
                ChouJiang_dianji_tx.SetActive(false);
                ChouJiang_dianji_tx.SetActive(true);
                Startrunbool = true;
                Txt_Huode.gameObject.SetActive(false);
                RangStop();
                AudioManagerP._instance.PlayAudio(2, "Anjian_2");
            }
            
        }
        private List<int> Fanbeinumberlist = new List<int>();
        private int FanbeiInt = 0;
        private void OnBtnfanbei()
        {
            if (GamePlayNengliang<=50)
            {
                Fanbeinumberlist = new List<int> { 1, 2, 3 };
            }
            if (GamePlayNengliang>50&& GamePlayNengliang<=100)
            {
                Fanbeinumberlist = new List<int> { 1, 2, 3 ,5};
            }
            if (GamePlayNengliang>100)
            {
                Fanbeinumberlist = new List<int> { 1, 2, 3, 5 ,10};
            }
            FanbeiInt++;
            if (FanbeiInt>= Fanbeinumberlist.Count)
            {
                FanbeiInt = 0;
            }
            Btn_fanbei.transform.GetChild(0).GetComponent<Text>().text = Fanbeinumberlist[FanbeiInt].ToString();
        }

        private bool Startrunbool = false;
        private G2C_RunLaBa Runlaba;
        public async ETVoid OnStartLaba()
        {
            try
            {
                C2G_RunLaBa Runlabas = new C2G_RunLaBa();
                Runlabas.EnergyCount = Fanbeinumberlist[FanbeiInt];
                Log.Debug("发送的数据" + Runlabas);
               
               // Log.Debug("空=====" + SessionComponent.Instance.Session);
                Runlaba = (G2C_RunLaBa)await Game.Scene.GetComponent<SessionComponent>().Session.Call(Runlabas);//发送消息收到回调
                if (Runlaba.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("不成功" + Runlaba.Message);
                    return;

                }
                Log.Debug("回调成功");
                for (int i = 0; i < 3; i++)
                {
                    ArrIconsResult[i] = new int[5];
                    for (int j = 0; j < 5; j++)
                    {
                        int rand = UnityEngine.Random.Range(0, 6);
                        ArrIconsResult[i][j] = rand;
                    }    
                }
                ArrIconsResult[0][3] = Runlaba.Icos[0];
                ArrIconsResult[1][3] = Runlaba.Icos[1];
                ArrIconsResult[2][3] = Runlaba.Icos[2];
         
                //EnergySet(GamePlayNengliang);//无限能量
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }

        private G2C_PlayerInfo PlayerInfo;
        private async ETVoid SetPlayinfo() 
        {
            try
            {
                G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());//发送消息收到回调
                if (g2CPlayerInfo.Error != ErrorCode.ERR_Success) //不成功
                {
                    return;
                }
                PlayerInfo = g2CPlayerInfo;
                Log.Debug("自己金币" + g2CPlayerInfo.Info.GoldCoins + "    自己星星" + g2CPlayerInfo.Info.Lev + "         自己能量" + g2CPlayerInfo.Info.Energy);
                GamePlayXingxing = g2CPlayerInfo.Info.Lev;
                Txt_Xingxing.text = g2CPlayerInfo.Info.Lev.ToString();

                GamePlayGoid = g2CPlayerInfo.Info.GoldCoins;
                Txt_Goid.text = Numdispose(g2CPlayerInfo.Info.GoldCoins.ToString());

                GamePlayHudun = g2CPlayerInfo.Info.HuDun;
                for (int i = 1; i < 4; i++)
                {
                    Obj_hudun.transform.GetChild(i).gameObject.SetActive(false);
                }
                for (int i = 1; i < GamePlayHudun+1; i++)
                {
                    Obj_hudun.transform.GetChild(i).gameObject.SetActive(true);
                }
                Txt_MoreName.text = g2CPlayerInfo.Info.NickName;
                Image_moretouxiang.sprite = await Load(g2CPlayerInfo.Info.FaceUrl);
                EnergySet(g2CPlayerInfo.Info.Energy);
                FanbeiInt = -1;
                OnBtnfanbei();
                DoubleClikeButton.Instance.CaCallBack = Onstartbutton;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }

        //设置数字单位
        public  string Numdispose(string num)
        {
            string[] symbol = { "K", "M", "B", "T", "aa", "ab", "ac", "ad" };

            string str1 = string.Empty;

            string str2 = string.Empty;

            if (num.Length > 6)
            {
                int a = (num.Length - 6) / 3;

                str1 = num.Substring(0, (num.Length - (3 * (a + 1))));

                int b = num.Length - (3 * (a + 1));

                str2 = num[b].ToString();

                if (int.Parse(str2) >= 5) str1 = (int.Parse(str1) + 1).ToString();

                if (str1.Length > 3) return str1.Insert(str1.Length - 3, ",") + symbol[a];

                return str1 + symbol[a];
            }
            if (num.Length > 3 && num.Length < 7)
            {
                return num.Insert(num.Length - 3, ",");
            }
            return num;
        }

        public void EnergySet(int print,int status,long enregvtime)
        {
                Timetimes = enregvtime;
                Timeenregv = print;
               Zongenregv = status+ print;
                if (!daojishibool)
                {
                    Timedaoji();
                }
            EnergySet(status);
            //身上的能量  总能量  倒计时



        }
        private void EnergySet(int print) 
        {
            GamePlayNengliang = print;
            Txt_NengliangTxt.text = GamePlayNengliang+"/50";
            if (GamePlayNengliang >= 50)
            {
                Timetimes = 0;
                Obj_daojishiobj.SetActive(false);
                Txt_Daojishi.text = "Energy is full";
                Img_Jindutiao.fillAmount = 1;
                if (GamePlayNengliang>50)
                {
                    Txt_nengliang.gameObject.SetActive(true);
                    Txt_nengliang.text = "+" + (GamePlayNengliang - 50);
                    Txt_NengliangTxt.text =  "50/50";
                }
               
            }
            else
            {

                Txt_nengliang.gameObject.SetActive(false);
                Log.Debug("当前能量:" + print + "         剩余:" + print * 2 + "             操作之后:" + (print * 2) / (float)100);
                float fl = (print * 2) / (float)100;
                Img_Jindutiao.fillAmount = fl;
                Txt_nengliang.gameObject.SetActive(false);
            }

        }
        private void ToRun()
        {

        }
        String Timedaojistr;
        private long Timetimes;//倒计时txt
        private int Timeenregv;//获得的能量
        private int Zongenregv;
        private bool daojishibool = false;
        public async void Timedaoji()
        {
            daojishibool = true;
            Log.Debug("开始倒计时" + Timetimes);
            while (true)
            {
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);//1000是一秒
                Timetimes--;
                if (Timetimes>0)
                {
                    Obj_daojishiobj.SetActive(true);
                    Timedaojistr = Timetimes / 60 + "Min" + Timetimes % 60 + "S";
                    Txt_Daojishi.text = Timedaojistr;
                   // Txt_Daojishi.text ="get"+ Timeenregv + " Energy" + "in" + Timedaojistr;
                }
            }        
        }

        //转动结束.
        private void RollStop() 
        {
            Log.Debug("道具id" + Runlaba.TypeID + "道具数量" + Runlaba.Count + "玩家获得金币" + Runlaba.Money);
            foreach (Transform child in Obj_Texiao.transform)
            {
                child.gameObject.SetActive(false);
            }
            switch (Runlaba.TypeID)
            {
                case (int)LaBaType.PaoTai://炮台
                    Obj_Texiao.transform.Find("ChouJiang_gongji_tx").gameObject.SetActive(true);
                     AudioManagerP._instance.PlayAudio(1, "Chouzhong_gongji_diandai");
                    break;
                case (int)LaBaType.HuDun://护盾
                    AudioManagerP._instance.PlayAudio(1, "Chouzhong_dunpai"); 
                    Obj_Texiao.transform.Find("HuDun_zhongjiang_tx").gameObject.SetActive(true);
                    break;
                case (int)LaBaType.YaoPin://药品
                    AudioManagerP._instance.PlayAudio(1, "nengliang_huirunengliangkuang1");
                    Obj_Texiao.transform.Find("ChouJiang_nengliang_tx").gameObject.SetActive(true);
                    break;
                case (int)LaBaType.DaoZei://盗贼
                     AudioManagerP._instance.PlayAudio(1, "zhunbeitouxi_touxiao1");
                    Obj_Texiao.transform.Find("ChouJiang_dianji_tx").gameObject.SetActive(true);
                    break;
                case (int)LaBaType.JinBi://金币
                    Obj_Texiao.transform.Find("ChouJiang_jinbi_tx").gameObject.SetActive(true);
                    AudioManagerP._instance.PlayAudio(1, "Jinbi_yinxiao"); 
                    break;
                case   (int)LaBaType.QianDai://钱带
                    Obj_Texiao.transform.Find("ChouJiang_qiandai_tx").gameObject.SetActive(true);
                    break;
                case (int)LaBaType.Null://null

                    break;
            }
  
            if (Runlaba.Money>0)
            {
                Obj_Texiao.transform.Find("ChouJiang_jinbi_tx").gameObject.SetActive(true);
                Txt_Huode.gameObject.SetActive(true);
                Txt_Huode.text = Runlaba.Money.ToString();
                GamePlayGoid += Runlaba.Money;
                Txt_Goid.text = Numdispose(GamePlayGoid.ToString());

            }
            if (Runlaba.Energy>0)
            {
                EnergySet(GamePlayNengliang + Runlaba.Energy);

            }
            if (!Runbool)
            {
                RangStart();
            }       
            Xianshitexiao(Runlaba.TypeID, Runlaba.Count);
        }
        public async void Xianshitexiao(int TypeID,int count )
        {
            Log.Debug("当前id" + TypeID);
            await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);//1000是一秒
            for (int i = 0; i < Obj_Texiao.transform.childCount; i++)
            {
                Obj_Texiao.transform.GetChild(i).gameObject.SetActive(false);

            }
            Startrunbool = false;
            switch (TypeID)
            {
                case (int)LaBaType.PaoTai://炮台
                    Obj_Guochang.SetActive(true);
                    GameActivefalse(Obj_Guochang, 1000);
                    GetEnemyInfo().Coroutine();
                    break;
                case (int)LaBaType.HuDun://护盾
                    GamePlayHudun += count;
                    if (GamePlayHudun<=3)
                    {
                        for (int i = 1; i < GamePlayHudun + 1; i++)
                        {
                            Obj_hudun.transform.GetChild(i).gameObject.SetActive(true);
                        }

                    }
                  
                    break;
                case (int)LaBaType.YaoPin://药品
 
                    if (Runbool)
                    {
                        StartButton();
                    }

                    break;
                case (int)LaBaType.DaoZei://盗贼
                    TouquEnemy().Coroutine();

                    break;
                case (int)LaBaType.JinBi://金币

                    if (Runbool)
                    {
                        StartButton();
                    }

                    break;
                case (int)LaBaType.QianDai://强盗


                    break;
                case (int)LaBaType.Null://null
                    if (Runbool)
                    {
                        StartButton();
                    }

                    break;
            }
         
        }
        //延迟后两秒显示.传入需要隐藏的物体和隐藏的时间
        public async void GameActivefalse(GameObject obj, int number)
        {
            await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(number);//1000是一秒
            obj.gameObject.SetActive(true);
        }
        private bool Zhengqibool = false;

        //开始滚动
       public  void StartRoll(Action fun )
        {
            Zhengqibool = true;
            _function = fun;
            Log.Debug("开始运行");
            if (Zhengqibool)//整启整停
            {
                ArrIconStatus = new int[] { 1, 1, 1 };
                iArrRollCnt = new int[] { 3, 3, 3 };
                IEStop();
                IERollBegin();

            }
            else//整启分停
            {
                ArrIconStatus = new int[] { 1, 1, 1 };
                iArrRollCnt = new int[] { 2, 3, 4 };
                IEStop();
                IERollBegin();
            }
           
        }

        //设置位置
        private void SetMoveVector()
        {
            int RollSpeed = 80;//每次移动像素
            int rollCnt = 1200 / RollSpeed;
            DicIconVector = new Dictionary<int, Vector3>();
            for (int i = 0; i <= rollCnt; i++)
            {
                DicIconVector.Add(720 - RollSpeed * i, new Vector3(0, (720 - RollSpeed * i) - RollSpeed, 0));
            }
            DicIconVector[-480] = new Vector3(0, 720, 0);
        }
        public async void IEStop()
        {
            bool isstopBool = true;
            while (isstopBool)
            {
              
                for (int i = 0; i < 3; i++)
                {
                    await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(500);//1000是一秒
                    ArrIconStatus[i] = 2;
                }
                isstopBool = false;
                Log.Debug("设置停止的时间");
            }

           
        }

        //滚动
        public async void IERollBegin()
        {
            bool bRoll = true;
            DownRollBool = true;
            ChouJiang_zhuanpan_tx.SetActive(true);
            AudioManagerP._instance.StopAudio(1);
            AudioManagerP._instance.PlayAudio(1, "Chouzhong_gongji_diandai");
            while (bRoll)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (ArrIconStatus[i] == 1 || (ArrIconStatus[i] == 2 && iArrRollCnt[i] > 0))
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Icons[i][j].localPosition = DicIconVector[(int)Icons[i][j].localPosition.y];
                            if ((ArrIconStatus[i] == 1 || ArrIconStatus[i] == 2) && (int)Icons[i][j].localPosition.y == 720 && iArrRollCnt[i] > 1)
                            {
                                int rand = UnityEngine.Random.Range(0, 6);
                                Icons[i][j].GetComponent<Image>().sprite = BlurredPicture[rand];
                            }
                            else if (ArrIconStatus[i] == 2 && (int)Icons[i][j].localPosition.y == 720 && iArrRollCnt[i] == 1)
                            {
                              
                                Icons[i][j].GetComponent<Image>().sprite = ImgIcon[ArrIconsResult[i][j]];
                            }
                        }
                        if (ArrIconStatus[i] == 2 && (int)Icons[i][4].localPosition.y == -240)
                        {
                            iArrRollCnt[i]--;
                            if (iArrRollCnt[i] == 0) ArrIconStatus[i] = 3;
                        }
                        //开始倒滚
                        if (ArrIconStatus[i] == 3 && iArrRollCnt[i] == 0)
                        {
                            ArrIconStatus[i] = 4;
                            //  IEDownRoll(i);
                            if (i == 2)
                            {
                                bRoll = false;
                                ChouJiang_zhuanpan_tx.SetActive(false);
                                ChouJiang_dianji_tx.SetActive(false);
                                AudioManagerP._instance.StopAudio(1);
                                _function();
                            }
                                
                        }
                    }

                }
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(0);//1000是一秒
            }
        }


        private bool DownRollBool = true;
        //倒滚
        public async void IEDownRoll(int i)
        {
            Log.Debug("开始倒滚"+i);
            ArrIconStatus[i] = 0;
            while (DownRollBool)
            {

                for (int iconY = -300; iconY <= -240; iconY += 10)
                {
                    for (int downIcon = 0; downIcon < 5; downIcon++)
                    {
                        Icons[i][downIcon].localPosition = new Vector3(0, iconY + (4 - downIcon) * 240, 0);
                    }
                    await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1);//1000是一秒
                }
            }
                if (i == 2)
                {
                    DownRollBool = false;
               
                }
            
           
        }


        //匹配敌人
        private G2C_MatchMessage matchinfos;
        public async void MatchEnemy(G2C_MatchMessage matchinfo) 
        {
            Txt_name.text = matchinfo.NickName;
            Txt_DIrengoid.text = Numdispose(matchinfo.GoldCoins.ToString());
            Img_touxiang.sprite = await Load(matchinfo.FaceUrl);
            matchinfos = matchinfo; 

        }
        // ImageFormat
        public async ETTask<Sprite> Load(string str)
        {
            Log.Debug("当前网站" + str);
            Sprite sprite = null;
            using (UnityWebRequest request = new UnityWebRequest(str))
            {
                DownloadHandlerTexture downloadHandlerTexture = new DownloadHandlerTexture(true);
                request.downloadHandler = downloadHandlerTexture;
                request.SendWebRequest();
                while (!request.isDone)
                {
                    await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(10);
                }
                if (string.IsNullOrEmpty(request.error))
                {
                    Texture2D localTexture = downloadHandlerTexture.texture;
                    sprite = Sprite.Create(localTexture, new Rect(0, 0, localTexture.width, localTexture.height), new Vector2(0.5f, 0.5f));
                    return sprite;
                }
                else
                {
  
                    Debug.Log(request.error);
                }
            }
            return sprite;
        }
         private void Tiaozhuan1()
        {  
            ScrollViewMoreSlide.Instance.Tonumberye(1);//大概
        }
        private void Tiaozhuan2()
        {
            //ScrollViewMoreSlide.Instance.Tonumberye(2);
        }
        private void Tiaozhuan3()
        {
          //  ScrollViewMoreSlide.Instance.Tonumberye(3);
           ScrollViewMoreSlide.Instance.Tonumberye(2);
        }
        private void Tiaozhuan4()
        {
            //  ScrollViewMoreSlide.Instance.Tonumberye(4);
            ScrollViewMoreSlide.Instance.Tonumberye(3);
        }
        private void Tiaozhuan5()
        {
           // ScrollViewMoreSlide.Instance.Tonumberye(5);
        }
        private void OnSlCallBack(float fl) 
        {
            //图标 90,270,450,630,810,990
            //  -447,-267,-87,93,273,453
            //线 180  360  540  720 900
            // -357   -177  3   183   363
            AudioManagerP._instance.PlayAudio(2, "Anjian_2");
            Log.Debug("开始移动============================="+fl);
            if (fl ==3)
            {
                GetMaps().Coroutine();
                if (!OnbenxiajiangBool)
                {
                    OnBtnXiajiang();
                }

            }
            else
            {
                if (OnbenxiajiangBool)
                {
                    OnBtnXiajiang();
                }
            }



            //if (fl == 2)
            //{
            //    GetKapai().Coroutine();
            //}
            //if (fl == 5)
            //{
            //    GetFuchou().Coroutine();
            //}
            switch (fl)
            {
                case 1:
                    Btn_fangzi.GetComponent<Image>().sprite = sdda;  //修改图片
                    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                    Btn_fangzi.transform.localPosition = new Vector3(-360, 40, 0);
                    Btn_laba.gameObject.SetActive(true);
                    Btn_zhuye.gameObject.SetActive(false);
                    Btn_chuizi.GetComponent<Image>().sprite = ct; //修改图片
                    Btn_chuizi.GetComponent<Image>().SetNativeSize();
                    Btn_chuizi.transform.localPosition = new Vector3(370, 3, 0);
                    break;
                case 2:
                    Btn_laba.gameObject.SetActive(false);
                    Btn_zhuye.gameObject.SetActive(true);
                    Btn_fangzi.GetComponent<Image>().sprite = sd;    //修改图片
                    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                    Btn_fangzi.transform.localPosition = new Vector3(-360, 3, 0);
                    Btn_chuizi.GetComponent<Image>().sprite = ct;    //修改图片
                    Btn_chuizi.GetComponent<Image>().SetNativeSize();
                    Btn_chuizi.transform.localPosition = new Vector3(370, 3, 0);
                    break;
                case 3:
                      Btn_chuizi.GetComponent<Image>().sprite = ctda;   //修改图片
                      Btn_chuizi.GetComponent<Image>().SetNativeSize();
                      Btn_chuizi.transform.localPosition = new Vector3(370, 40, 0);
                    Btn_laba.gameObject.SetActive(true);
                    Btn_zhuye.gameObject.SetActive(false);
                    Btn_fangzi.GetComponent<Image>().sprite = sd;     //修改图片
                    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                    Btn_fangzi.transform.localPosition = new Vector3(-360, 3, 0);
                    break;

            }
            switch (fl)
            {
                //case 1:
                //    #region
                //    Btn_fangzi.GetComponent<Image>().sprite = sdda;  //修改图片
                //    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                //    Btn_fangzi.transform.localPosition = new Vector3(-357, 20, 0);
                //    for (int i = 0; i < xianlist.Count; i++)
                //    {
                //        xianlist[i].SetActive(true);

                //    }
                //    Log.Debug("======1111" );
                //    Log.Debug("======11112222");
                //    Toushang.SetActive(true);
                //    jianzhu_wancheng_star02_tx.SetActive(false);
                //    xianlist[0].SetActive(false);
                //    Btn_laba.gameObject.SetActive(true);
                //    Btn_zhuye.gameObject.SetActive(false);
                //    Btn_kapai.GetComponent<Image>().sprite = kp;   //修改图片
                //    Btn_kapai.GetComponent<Image>().SetNativeSize();
                //    Btn_laba.GetComponent<Image>().sprite = zhuye;   //修改图片
                //    Btn_laba.GetComponent<Image>().SetNativeSize();
                //    Btn_chuizi.GetComponent<Image>().sprite = ct; //修改图片
                //    Btn_chuizi.GetComponent<Image>().SetNativeSize();
                //    Btn_zhadan.GetComponent<Image>().sprite = cr;    //修改图片
                //    Btn_zhadan.GetComponent<Image>().SetNativeSize();
                //    Btn_kapai.transform.localPosition = new Vector3(-87, 0, 0);
                //    Btn_laba.transform.localPosition = new Vector3(93, 0, 0);
                //    Btn_chuizi.transform.localPosition = new Vector3(273, 0, 0);
                //    Btn_zhadan.transform.localPosition = new Vector3(453, 0, 0);
                //    break;
                //#endregion
                //case 2:
                //    #region
                //    Btn_kapai.GetComponent<Image>().sprite = kpda;   //修改图片
                //    Btn_kapai.GetComponent<Image>().SetNativeSize();
                //    Btn_kapai.transform.localPosition = new Vector3(-177, 20, 0);
                //    for (int i = 0; i < xianlist.Count; i++)
                //    {
                //        xianlist[i].SetActive(true);
                //    }
                //    xianlist[1].SetActive(false);
                //    Toushang.SetActive(false);
                //    jianzhu_wancheng_star02_tx.SetActive(false);
                //    Btn_laba.gameObject.SetActive(true);
                //    Btn_zhuye.gameObject.SetActive(false);
                //    Btn_fangzi.GetComponent<Image>().sprite = sd;    //修改图片
                //    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                //    Btn_laba.GetComponent<Image>().sprite = zhuye;   //修改图片
                //    Btn_laba.GetComponent<Image>().SetNativeSize();
                //    Btn_chuizi.GetComponent<Image>().sprite = ct;   //修改图片
                //    Btn_chuizi.GetComponent<Image>().SetNativeSize();
                //    Btn_zhadan.GetComponent<Image>().sprite = cr; //修改图片
                //    Btn_zhadan.GetComponent<Image>().SetNativeSize();
                //    Btn_fangzi.transform.localPosition = new Vector3(-477, 0, 0);
                //    Btn_laba.transform.localPosition = new Vector3(93, 0, 0);
                //    Btn_chuizi.transform.localPosition = new Vector3(273, 0, 0);
                //    Btn_zhadan.transform.localPosition = new Vector3(453, 0, 0);
                //    break;
                //#endregion
                //case 3:
                //    #region
                //    Btn_laba.gameObject.SetActive(false);
                //    Btn_zhuye.gameObject.SetActive(true);
                //    for (int i = 0; i < xianlist.Count; i++)
                //    {
                //        xianlist[i].SetActive(true);
                //    }
                //    Toushang.SetActive(true);
                //    xianlist[2].SetActive(false);
                //    jianzhu_wancheng_star02_tx.SetActive(false);
                //    Btn_fangzi.GetComponent<Image>().sprite = sd;    //修改图片
                //    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                //    Btn_kapai.GetComponent<Image>().sprite = kp;    //修改图片
                //    Btn_kapai.GetComponent<Image>().SetNativeSize();
                //    Btn_chuizi.GetComponent<Image>().sprite = ct;    //修改图片
                //    Btn_chuizi.GetComponent<Image>().SetNativeSize();
                //    Btn_zhadan.GetComponent<Image>().sprite = cr;  //修改图片
                //    Btn_zhadan.GetComponent<Image>().SetNativeSize();
                //    Btn_fangzi.transform.localPosition = new Vector3(-447, 0, 0);
                //    Btn_kapai.transform.localPosition = new Vector3(-267, 0, 0);
                //    Btn_chuizi.transform.localPosition = new Vector3(273, 0, 0);
                //    Btn_zhadan.transform.localPosition = new Vector3(453, 0, 0);
                //    break;
                //#endregion
                //case 4:
                //    #region
                //    Btn_chuizi.GetComponent<Image>().sprite = ctda;   //修改图片
                //    Btn_chuizi.GetComponent<Image>().SetNativeSize();
                //    Btn_chuizi.transform.localPosition = new Vector3(183, 20, 0);
                //    for (int i = 0; i < xianlist.Count; i++)
                //    {
                //        xianlist[i].SetActive(true);

                //    }
                //    xianlist[3].SetActive(false);
                //    Btn_laba.gameObject.SetActive(true);
                //    Btn_zhuye.gameObject.SetActive(false);
                //    Toushang.SetActive(true);
                //    jianzhu_wancheng_star02_tx.SetActive(false);
                //    Btn_fangzi.GetComponent<Image>().sprite = sd;     //修改图片
                //    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                //    Btn_laba.GetComponent<Image>().sprite = zhuye;  //修改图片
                //    Btn_laba.GetComponent<Image>().SetNativeSize();
                //    Btn_kapai.GetComponent<Image>().sprite = kp;  //修改图片
                //    Btn_kapai.GetComponent<Image>().SetNativeSize();
                //    Btn_zhadan.GetComponent<Image>().sprite = cr;   //修改图片
                //    Btn_zhadan.GetComponent<Image>().SetNativeSize();

                //    Btn_fangzi.transform.localPosition = new Vector3(-447, 0, 0);
                //    Btn_kapai.transform.localPosition = new Vector3(-267, 0, 0);
                //    Btn_laba.transform.localPosition = new Vector3(-87, 0, 0);
                //    Btn_zhadan.transform.localPosition = new Vector3(453, 0, 0);
                //    break;
                //#endregion
                //case 5:
                //    #region
                //    Btn_zhadan.GetComponent<Image>().sprite = crda;   //修改图片
                //    Btn_zhadan.GetComponent<Image>().SetNativeSize();
                //    Btn_zhadan.transform.localPosition = new Vector3(363, 20, 0);
                //    for (int i = 0; i < xianlist.Count; i++)
                //    {
                //        xianlist[i].SetActive(true);

                //    }
                //    Toushang.SetActive(false);
                //    jianzhu_wancheng_star02_tx.SetActive(false);
                //    xianlist[4].SetActive(false);
                //    Btn_laba.gameObject.SetActive(true);
                //    Btn_zhuye.gameObject.SetActive(false);
                //    Btn_fangzi.GetComponent<Image>().sprite = sd;   //修改图片
                //    Btn_fangzi.GetComponent<Image>().SetNativeSize();
                //    Btn_laba.GetComponent<Image>().sprite = zhuye;    //修改图片
                //    Btn_laba.GetComponent<Image>().SetNativeSize();
                //    Btn_kapai.GetComponent<Image>().sprite = kp;    //修改图片
                //    Btn_kapai.GetComponent<Image>().SetNativeSize();
                //    Btn_chuizi.GetComponent<Image>().sprite = ct;   //修改图片
                //    Btn_chuizi.GetComponent<Image>().SetNativeSize();


                //    Btn_fangzi.transform.localPosition = new Vector3(-447, 0, 0);
                //    Btn_kapai.transform.localPosition = new Vector3(-267, 0, 0);
                //    Btn_laba.transform.localPosition = new Vector3(-87, 0, 0);
                //    Btn_chuizi.transform.localPosition = new Vector3(93, 0, 0);
                //    break;
                //    #endregion
                default:
                    break;
            }
        }


        //攻击之前获取敌人信息
        private bool attacling;
        private List<int> jianzhulvlist = new List<int>();//打之前的建筑物等级.打完之后判断是否消失还是存在显示特效
        private int ditulv;//打之前的地图等级
        private async ETVoid GetEnemyInfo()
        {
            try
            {
                Log.Debug("开始发送获取敌人信息");
                G2C_GetEnemyInfo g2GetEnemyInfo = (G2C_GetEnemyInfo)await SessionComponent.Instance.Session.Call(new C2G_GetEnemyInfo());//发送消息收到回调
                if (g2GetEnemyInfo.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug(g2GetEnemyInfo.Message);
                    return;
                }
                //  g2GetEnemyInfo.level;//地图等级
                // g2GetEnemyInfo.Levs ;//当前等级
                //g2GetEnemyInfo.MaxLevs ;//最高等级
                Log.Debug("成功获得回调");
                Txt_attackname.text = matchinfos.NickName;
                Ima_attacktx.sprite = await Load(matchinfos.FaceUrl);
                Obj_Attack.SetActive(true);
                AudioManagerP._instance.PlayBGMAudio("GongjiBGM1");
                Obj_attackover.SetActive(false);
                Btn_REVENGE.gameObject.SetActive(true);
                Obj_AttackInfoback.SetActive(true);
                Attackanimator.SetBool("Attackbool", false);
                jianzhu_paoche_tx.transform.GetChild(1).gameObject.SetActive(false);
                GameActivefalse(jianzhu_paoche_tx, 1000);
                jianzhulvlist.Clear();
                for (int i = 1; i < 6; i++)
                {
                    Obj_Attack.transform.Find("_" + i).transform.GetChild(2).gameObject.SetActive(false);

                }
                for (int i = 0; i < 5; i++)
                {
                    if (g2GetEnemyInfo.Levs[i]>0)//如果当前等级大于零 显示当前等级的图片
                    {
                      //  Log.Debug("地图等级:" + (g2GetEnemyInfo.Level + 1) + "    当前等级" + (g2GetEnemyInfo.Levs[i]) + "   i="+ (i + 1));
                        Obj_Attack.transform.Find("_" + (i+1)).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>((g2GetEnemyInfo.Level + 1) + "_" + (g2GetEnemyInfo.Levs[i]) + "_" + (i+1));
                        Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().SetNativeSize();
                        Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 1); ;
                        GameActivefalse(Obj_Attack.transform.Find("_" + (i + 1)).GetChild(0).gameObject, 1000);
                        Obj_Attack.transform.Find("_" + (i + 1)).GetChild(1).gameObject.SetActive(true);
                        Obj_Attack.transform.Find("_" + (i + 1)).GetChild(2).gameObject.SetActive(false);
                    }
                    else
                    {
                        Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 0.01f);;
                    }

                    if (g2GetEnemyInfo.MaxLevs[i] > g2GetEnemyInfo.Levs[i])//被攻击了的建筑物.显示被攻击特效
                    {
                        Obj_Attack.transform.Find("_" + (i + 1)).GetChild(3).gameObject.SetActive(true);
                    }
                    jianzhulvlist.Add(g2GetEnemyInfo.Levs[i]);
                }
                ditulv = g2GetEnemyInfo.Level + 1;
                if (g2GetEnemyInfo.Levs[0]==0&& g2GetEnemyInfo.Levs[1] == 0&& g2GetEnemyInfo.Levs[2] == 0&& g2GetEnemyInfo.Levs[3] == 0&& g2GetEnemyInfo.Levs[4] == 0)
                {
                    attacling = true;
                    Obj_Attackling.SetActive(true);
                    GameActivefalse(Obj_Attackling.transform.GetChild(0).gameObject, 1000);
                    Obj_Attackling.transform.GetChild(2).gameObject.SetActive(true);
                }
                else
                {
                    Obj_Attackling.SetActive(false);
                    Obj_Attackling.transform.GetChild(0).gameObject.SetActive(false);
                    Obj_Attackling.transform.GetChild(1).gameObject.SetActive(false);
                    Obj_Attackling.transform.GetChild(2).gameObject.SetActive(false);
                }
                Txt_attackms.text = "地图等级" + (g2GetEnemyInfo.Level + 1);

            }
            catch (Exception e)
            {

                Log.Error(e);
            }
        }


        //开始攻击
        private void Startatt(int print)
        {
            Log.Debug("获得的点" + print);
            StartAttack(print).Coroutine();
        }

        private void OnAttackItem() 
        {
           
            Obj_Attack.gameObject.SetActive(false);
            Obj_Attackfuchou.transform.localScale = new Vector3(1, 1, 1);
            Obj_Attackfuchou.SetActive(true);


        }

        private bool DirenHudunbool = false;
         private async ETVoid StartAttack(int print) 
          {
            try
            {
                Log.Debug("发送得点是" + print);
                C2G_AttackEnemy attackenemy = new C2G_AttackEnemy();
                attackenemy.Index = print;
                   G2C_AttackEnemy g2Attacjenemy = (G2C_AttackEnemy)await SessionComponent.Instance.Session.Call(attackenemy);//发送消息收到回调
                if (g2Attacjenemy.Error != ErrorCode.ERR_Success) //不成功
                {
                    return;
                }
                if (g2Attacjenemy.HuDun==0)//没有护盾.1代表有
                {
                    DirenHudunbool = false;
                }
                else
                {
                    DirenHudunbool = true;
                }
                for (int i = 0; i < 5; i++)
                {
                    Obj_Attack.transform.GetChild(i).GetChild(1).gameObject.SetActive(false);
                 
                }
                Obj_Attackling.transform.GetChild(2).gameObject.SetActive(false);
                Attackasync(print, g2Attacjenemy.GoldCoins);

                Log.Debug("获得的金币" + g2Attacjenemy.GoldCoins);
               

               
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

        }
        public async void Attackasync(int print,long goid)
        {
            Log.Debug("当前是======="+print);
            float miaozhunfl = 1;
            for (int i = 0; i < 10; i++)
            {
                miaozhunfl -= 0.1f;
                for (int j = 0; j < 5; j++)
                {
                    Obj_Attack.transform.GetChild(j).GetChild(0).localScale = new Vector3(miaozhunfl, miaozhunfl, 1);
                    if (attacling)
                    {
                        Obj_Attackling.transform.GetChild(0).localScale = new Vector3(miaozhunfl, miaozhunfl, 1);
                    }
                }
                
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(50);//1000是一秒
            }
            for (int i = 0; i < 5; i++)
            {
                Obj_Attack.transform.GetChild(i).GetChild(0).gameObject.SetActive(false);
                Obj_Attack.transform.GetChild(i).GetChild(0).localScale = new Vector3(1, 1, 1);
            }
            Obj_Attackling.transform.GetChild(0).gameObject.SetActive(false);
            Obj_Attackling.transform.GetChild(0).localScale = new Vector3(1, 1, 1);
            Attackanimator.SetBool("Attackbool", true);
            await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(180);//1000是一秒
            jianzhu_paoche_tx.transform.GetChild(1).gameObject.SetActive(true);
            await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(500);//1000是一秒g
            jianzhu_paoche_tx.transform.GetChild(1).gameObject.SetActive(false);
            Obj_Attackling.transform.GetChild(1).gameObject.SetActive(true);
            jianzhulvlist[print] -= 1; 
          
            if (DirenHudunbool)//对方有没有护盾
            {
                AudioManagerP._instance.PlayAudio(1, "Dunpaidangzhugongji"); 
                Obj_Attack.transform.Find("Obj_Hudunchuxian").gameObject.SetActive(true);
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);//1000是一秒
            }
            else
            {
                AudioManagerP._instance.PlayAudio(1, "Gongji_paodanbaozha1");
                Obj_Attack.transform.Find("_" + (print + 1)).transform.GetChild(2).gameObject.SetActive(true);
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1500);//1000是一秒
            }

            jianzhu_paoche_tx.gameObject.SetActive(false);
          
            if (jianzhulvlist[print] > 0)
            {
                Obj_Attack.transform.Find("_" + (print + 1)).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>(ditulv + "_" + jianzhulvlist[print] + "_" + (print + 1));
                Obj_Attack.transform.Find("_" + (print + 1)).GetChild(3).gameObject.SetActive(true);
            }
            else
            {
                Obj_Attack.transform.Find("_" + (print + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 0.01f);
                Obj_Attack.transform.Find("_" + (print + 1)).GetChild(3).gameObject.SetActive(true);
            }
            
            Obj_Attackling.transform.GetChild(1).gameObject.SetActive(false);
            Txt_attackoverms.text = "在攻击中获得了<color=#D9D919><size=60>" + Numdispose(goid.ToString()) + "</size></color>金币<color=#8E236B><size=60>是别人家的</size></color>";
            GamePlayGoid += goid;
            Txt_Goid.text = Numdispose(GamePlayGoid.ToString());
            Obj_AttackInfoback.SetActive(false);
            Obj_attackover.SetActive(true);
        }
        private void AttackOver() 
        {
            Obj_Guochang.SetActive(true);
            GameActivefalse(Obj_Guochang, 1000);
            Obj_Attack.SetActive(false);
            AudioManagerP._instance.PlayBGMAudio("BGM1");
            if (Runbool)
            {
                StartButton();
            }
        }


        //偷取之前获取敌人信息
        private long TouquGoidInt = 0;
        private int TouquNumber = 0;
        private async ETVoid TouquEnemy()
        {
            try
            {
                G2C_GetEnemyInfo g2GetEnemyInfo = (G2C_GetEnemyInfo)await SessionComponent.Instance.Session.Call(new C2G_GetEnemyInfo());//发送消息收到回调
                if (g2GetEnemyInfo.Error != ErrorCode.ERR_Success) //不成功
                {
                    return;
                }
                //  g2GetEnemyInfo.level;//地图等级
                // g2GetEnemyInfo.Levs ;//当前等级
                //g2GetEnemyInfo.MaxLevs ;//最高等级
                AudioManagerP._instance.PlayBGMAudio("TouxiBgm");
                Log.Debug("玩家名字" + matchinfos.NickName);
                Txt_Touquname.text = matchinfos.NickName;
                Txt_Touqugoid.text = Numdispose( matchinfos.GoldCoins.ToString());
                Ima_Touqutx.sprite = await Load(matchinfos.FaceUrl);
                Log.Debug("偷取获取信息成功");
                Obj_Touqu.SetActive(true);
                Obj_TouquInfoback.SetActive(true);
                Obj_Touquover.SetActive(false);
                TouquNumber = 3;
                TouquGoidInt = 0;
                Txt_Touqunumber.text = TouquGoidInt.ToString();
                for (int i = 0; i < 5; i++)
                {
                    
                        Log.Debug("地图等级:" + (g2GetEnemyInfo.Level + 1) + "    当前等级" + (g2GetEnemyInfo.Levs[i] + 1) + "   i=" + (i + 1));
                    if (g2GetEnemyInfo.Levs[i] > 0)
                    {
                        Obj_Touqu.transform.Find("_" + (i + 1)).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>((1) + "_" + (g2GetEnemyInfo.Levs[i]) + "_" + (i + 1));
                        Obj_Touqu.transform.Find("_" + (i + 1)).GetComponent<Image>().SetNativeSize();
                        Obj_Touqu.transform.Find("_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 1);
                    }
                    else
                    {
                        Obj_Touqu.transform.Find("_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 0.01f);
                    }
                   
                          
                        
                    if (g2GetEnemyInfo.MaxLevs[i] > g2GetEnemyInfo.Levs[i])//判断当前建筑物是否被攻击过
                    {
                        Obj_Touqu.transform.Find("_" + (i + 1)).transform.GetChild(0).gameObject.SetActive(true);
                    }
                    else
                    {
                        Obj_Touqu.transform.Find("_" + (i + 1)).transform.GetChild(0).gameObject.SetActive(false);
                    }
                    if (i<4)
                    {
                        Obj_Touqu.transform.Find("Tou"+i).gameObject.SetActive(true);//可攻击图标
                        Obj_Touqu.transform.Find("Tou" + i).GetComponent<Button>().enabled = true;
                    }
                }
            }
            catch (Exception e)
            {

                Log.Error(e);
            }
        }

        private void Starttq(int print)
        {
            Obj_Touqu.transform.Find("Tou" + print).GetComponent<Button>().enabled = false;
            Txt_touqutishi.gameObject.SetActive(false);
            Log.Debug("发送偷取信息"+print);
            StartTouqu(print).Coroutine();


        }
        private async ETVoid StartTouqu(int print)
            {
                try
                {
              
                C2G_StealEnemy touquenemy = new C2G_StealEnemy();
                touquenemy.Index = print;
                G2C_StealEnemy g2Attacjenemy = (G2C_StealEnemy)await SessionComponent.Instance.Session.Call(touquenemy);//发送消息收到回调
                    if (g2Attacjenemy.Error != ErrorCode.ERR_Success) //不成功
                   {
                    Txt_touqutishi.gameObject.SetActive(true);
                    Txt_touqutishi.text = g2Attacjenemy.Message;
                    Obj_Touqu.transform.Find("Tou" + print).gameObject.SetActive(false);
                    return;
                    }
                TouquNumber--;
                AudioManagerP._instance.PlayAudio(1, "TouxiChenggong_huodeyidian");
                Log.Debug("偷取的金币" + g2Attacjenemy.GoldCoins  + "剩下的次数"+ TouquNumber);
                Obj_Touqu.transform.Find("Tou" + print).gameObject.SetActive(false);
                TouquGoidInt += g2Attacjenemy.GoldCoins;
                Txt_Touqunumber.text = Numdispose(TouquGoidInt.ToString());
                if (TouquNumber==0)
                {
                    AudioManagerP._instance.PlayAudio(1, "TouxiChenggong_huodequanbu");
                    Obj_TouquInfoback.SetActive(false);
                    Txt_touquoverms.text = "在偷取中获得了<color=#FDC423><size=60>" + Numdispose(TouquGoidInt.ToString()) + "</size></color>金币<color=#8E236B><size=60>是别人家的</size></color>";
                    Obj_Touquover.SetActive(true);
                    for (int i = 0; i < 4; i++)
                    {
                        Obj_Touqu.transform.Find("Tou" + i).gameObject.SetActive(false);
                    }
                     GamePlayGoid += TouquGoidInt;
                    Txt_Goid.text = Numdispose( GamePlayGoid.ToString());
                }
                //g2Attacjenemy.GoldCoins  ;//偷得的金币 
            }
            catch (Exception e)
                {

                    Log.Error(e);
                }

            }
        private void TouquOver()
        {
            Log.Debug("偷完的时候" + Startrunbool);
            AudioManagerP._instance.PlayBGMAudio("BGM1");
            Obj_Guochang.SetActive(true);
            GameActivefalse(Obj_Guochang, 1000);
            Obj_Touqu.SetActive(false);//      Options FollowSymLinks ExecCGI
            if (Runbool)
            {
                StartButton();
            }
        }

        #endregion;

        #region//更多选项

        #region//更多选项进入页面
        private void OnBtnMorebangding()
        {
            Log.Debug("绑定facebook");
        }

        private void AmendInfo() 
        {
            Obj_AmendinfoBack.SetActive(true);
        }
        private void OnBtnRUnMore()
        {
            Obj_More.SetActive(true);
        }
        private void OnBtnExitMore()
        {
            Obj_More.SetActive(false);
        }

        private void OnRunyemian(int numbers)
        {
            Obj_More.SetActive(false);
            switch (numbers)
            {
                case 0://排行榜
                    GetRanklist().Coroutine();
                    Obj_RankingBack.SetActive(true);
                    break;
                case 1://排邀请召回
                    Obj_InvitationRecallBack.SetActive(true); 
                    break;
                case 2://vip
                    Obj_VipTc.SetActive(true);
                    break;
                case 3://地图
                    Obj_GuankaDitu.SetActive(true);
                    Obj_GuankaDitu.transform.localScale = new Vector3(1, 1, 1);
                    break;
                case 4://消息
                    Obj_MessageBack.SetActive(true);
                    Obj_MessageBack.transform.localScale = new Vector3(1, 1, 1);
                    break;
                case 5://设置
                    Obj_SettingBack.SetActive(true);
                    break;
                case 6://好友
                    Obj_FriendlBack.SetActive(true);
                    break;
                case 7://好友
                    Fuchou_Panel.SetActive(true);
                    Fuchou_Panel.transform.localScale = new Vector3(1, 1, 1);
                    break;
                default:
                    break;
            }
        }
        private void OnExitfuchoubang()
        {
            Fuchou_Panel.SetActive(false);
        }
        #endregion

        #region//排行榜
        private void OnBtnhaoyouRanking()
        {
            //Btn_haoyouRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_6");
            //Btn_shijieRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_5");
            //Btn_bendiRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_5");
        }

        private void OnBtn_hijieRanking()
        {
            //Btn_haoyouRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_5");
            //Btn_shijieRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_6");
            //Btn_bendiRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_5");
        
        }

        //获取世界排行榜
        private G2C_GetRankList g2rshijierangklist;
        private async ETVoid GetRanklist()
        {
            try
            {
                G2C_GetRankList g2rrangklist = (G2C_GetRankList)await SessionComponent.Instance.Session.Call(new C2G_GetRankList());//发送消息收到回调
                if (g2rrangklist.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================世界排行榜"+ g2rrangklist.Message);
                    return;
                }
                Log.Debug("==============世界排行榜");
                g2rshijierangklist = null;
                g2rshijierangklist = g2rrangklist;
                ScrollViewEx sve = Obj_ScrollView.GetComponent<ScrollViewEx>();
                //for (int i = 0; i < Obj_ScrollView.transform.GetChild(0).transform.childCount; i++)
                //{
                //    Destroy(Obj_ScrollView.transform.GetChild(0).transform.GetChild(i).gameObject);
                //}
                 sve.SetDataCount(g2rshijierangklist.Infos.count);
                sve.OnSetItem = ShijieRankItem;
                sve.ReSetScrollView();

            }
            catch (Exception e)
            {
                Log.Debug("==============列表");
                Log.Error(e);
            }
        }
        private void ShijieRankItem(Transform tra, int idex)
        {
            if (idex<3)
            {
                tra.transform.Find("Img_paihang").GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_"+(idex+1));
                tra.transform.Find("Img_paihang").GetComponent<Image>().SetNativeSize();
                tra.transform.Find("Img_paihang/Text").gameObject.SetActive(false);
            }
            else
            {
                tra.transform.Find("Img_paihang").GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_4");
                tra.transform.Find("Img_paihang").GetComponent<Image>().SetNativeSize();
                tra.transform.Find("Img_paihang/Text").GetComponent<Text>().text = (idex + 1).ToString();
                tra.transform.Find("Img_paihang/Text").gameObject.SetActive(true);
            }
            FuchouEnemy(tra.Find("touxiangkuang/Image/Img_RankingTouxiang").GetComponent<Image>(), g2rshijierangklist.Infos[idex].FaceUrl);
            tra.transform.Find("Txt_Rankingname").GetComponent<Text>().text = g2rshijierangklist.Infos[idex].NickName;
            tra.transform.Find("Image/Text").GetComponent<Text>().text = g2rshijierangklist.Infos[idex].Star.ToString();
            tra.gameObject.SetActive(true);
            tra.transform.localScale = new Vector3(1, 1, 1);
        }

        private void OnBtnbendiRanking()
        {
            Btn_haoyouRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_5");
            Btn_shijieRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_5");
            Btn_bendiRanking.GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Ranking_6");
        }

        private void OnBtnExitRanking()
        {
            Obj_RankingBack.SetActive(false);
            Obj_More.SetActive(true);
        }
        #endregion

        #region//邀请召回
        private void OnBtnrecall()
        {
            Btn_Invitation.GetComponent<Image>().sprite = rc.Get<Sprite>("Ranking_6");
            Btn_recall.GetComponent<Image>().sprite = rc.Get<Sprite>("Ranking_5");
          //  Facebooklogin.Instance.GetFBFriendInGame();
        }

        private void OnBtnInvitation()
        {
            Btn_Invitation.GetComponent<Image>().sprite = rc.Get<Sprite>("Ranking_5");
            Btn_recall.GetComponent<Image>().sprite = rc.Get<Sprite>("Ranking_6");
           // Facebooklogin.Instance.Fenxiang();
        }

        private void OnBtnExitInvitationRecall()
        {
            Obj_InvitationRecallBack.SetActive(false);
            Obj_More.SetActive(true);
        }
        #endregion

        #region//VIP
        private void OnBtnExitViptc()
        {
            Obj_VipTc.SetActive(false);
        }

        //购买周卡
        private void OnBtnVipWeek()
        {
      
        }


        //购买月卡
        private void OnBtnVIpMonth()
        {
         
        }


        #endregion

        #region//地图

        #endregion

        #region//消息
        private void OnBtnExitMessage()
        {
            Obj_MessageBack.SetActive(false);
        }

        private List<G2C_NoticeMessage> notiecelist = new List<G2C_NoticeMessage>();
        public void OnsetMessage(G2C_NoticeMessage  notice) 
        {
            Log.Debug("收到推送消息");
            Log.Debug("收到推送消息"+ Obj_MessageBack.name);
            Obj_MessageBack.transform.localScale = new Vector3(1, 1, 1);
            notiecelist.Add(notice);
            ScrollViewEx sve = Obj_Scrollhuadong.GetComponent<ScrollViewEx>();
            sve.SetDataCount(notiecelist.Count);
            sve.OnSetItem = OnsetMessageItem;
            sve.ReSetScrollView();

        }

        private void OnsetMessageItem(Transform tra, int idex) 
        {

            FuchouEnemy(tra.Find("touxiang/Image/Image").GetComponent<Image>(), notiecelist[idex].FaceUrl);
            tra.Find("touxiang/Image1/Text").GetComponent<Text>().text = notiecelist[idex].Star.ToString();
            tra.Find("name").GetComponent<Text>().text = notiecelist[idex].NickName;
            tra.Find("Text").GetComponent<Text>().text = notiecelist[idex].Context.ToString();
            Log.Debug("攻击类型" + notiecelist[idex].MsgType);
            switch (notiecelist[idex].MsgType)
            {
                case MsgEnum.Steal:
                    tra.Find("xingxing").GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Steal_0");
                    break;
                case MsgEnum.Attack:
                    Log.Debug("生成图片");
                    tra.Find("xingxing").GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Steal_1");
                    break;
                case MsgEnum.Defense:
                    tra.Find("xingxing").GetComponent<Image>().sprite = Gengduo.Get<Sprite>("Steal_2");
                    break;
                case MsgEnum.EnergyFull:
            
                    break;
                default:
                    break;
            }
           
            tra.localScale = new Vector3(1, 1, 1);
            tra.gameObject.SetActive(true);

        }
        #endregion

        #region//设置
        private bool SetyinxiaoBool = true;
        private bool SetyinyueoBool = true;
        private bool SetzhengdongBool = true;
        private bool SetliaotianBool;
        private bool SetVIPBool;

        private void OnBtnExiteSeting()
        {
            Obj_SettingBack.SetActive(false);
            Obj_More.SetActive(true);
        }



        private void OnBtnsettongzhi()
        {
         
        }





        private void OnBtnsetzhengdong()
        {
            SetzhengdongBool = !SetzhengdongBool;
            Qiehuan(Btn_setzhengdong.GetComponent<Image>(), SetzhengdongBool);
        }

        private void OnBtnsetyinyue()
        {
            SetyinyueoBool = !SetyinyueoBool;
            Qiehuan(Btn_setyinyue.GetComponent<Image>(), SetyinyueoBool);
        }

        private void OnBtnsetyinxiao()
        {
            SetyinxiaoBool = !SetyinxiaoBool;
            Qiehuan(Btn_setyinxiao.GetComponent<Image>(), SetyinxiaoBool);
        }

        //切换当前按钮的图片
        private void Qiehuan(Image spr, bool bo) 
        {
            if (bo)
            {
                spr.sprite = rc.Get<Sprite>("Setqueren");
            }
            else
            {
                 spr.sprite = rc.Get<Sprite>("Setforen");
            }
        
        }

        #endregion

        #region//好友
        private void OnBtnInviteFriends()
        {
            Facebooklogin.Instance.FBInvite("come");
        }

        private void OnBtnExitFriendl()
        {
            Obj_FriendlBack.SetActive(false);
            Obj_More.SetActive(true);
        }
        #endregion

        #region//修改个人信息
        private void OnBtnExitAmendinfo() 
        {
            Obj_AmendinfoBack.SetActive(false);
        }

             #endregion
        #endregion



        #region//关卡
        //获取地图
        private async ETVoid GetMaps()
        {
            try
            {
                Log.Debug("==============开始获取地图");
                G2C_GetMaps g2CGetMaps = (G2C_GetMaps)await SessionComponent.Instance.Session.Call(new C2G_GetMaps());//发送消息收到回调
                if (g2CGetMaps.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================不成功");
                    return;
                }
                Log.Debug("==============成功");
                GuankaInfo(g2CGetMaps);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }


        //建造界面当前信息
        private void GuankaInfo(G2C_GetMaps getmapsinfo)
        {
            Log.Debug("==============!成功huidiao");
            Txt_MapsName.text = "当前关卡" + (getmapsinfo.Level+1);
            shengchengditu(getmapsinfo.Level+1);
            for (int i = 0; i < 5; i++)
            {
                if (getmapsinfo.Levs[i] > 0)
                {
                    Obj_Jianchao.transform.Find("j_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 1);
                    Obj_Jianchao.transform.Find("j_" + (i + 1)).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>((1) + "_" + (getmapsinfo.Levs[i]) + "_" + (i + 1));
                }
                else
                {

                    Obj_Jianchao.transform.Find("j_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 0.01f);
                }
                Log.Debug("当前建筑物+"+i+"     最大等级为" + getmapsinfo.MaxLevs[i]);
                if (getmapsinfo.Levs[i] < getmapsinfo.MaxLevs[i])//建筑物被攻击掉级特效
                {
                    Obj_Jianchao.transform.Find("j_" + (i + 1)).transform.GetChild(1).gameObject.SetActive(true);
                }
                else
                {
                    Obj_Jianchao.transform.Find("j_" + (i + 1)).transform.GetChild(1).gameObject.SetActive(false);
                }


                if (getmapsinfo.Levs[i] != 5) //如果建筑物等级
                {
                    Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = true;//升级建筑按钮
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").gameObject.SetActive(true);
                        Obj_jianzhu.transform.GetChild(i).Find("Image").GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("0"+(1) + "_" + (getmapsinfo.Levs[i]+1) + "_" + (i+1));
                        Log.Debug("当前建筑等级========" + getmapsinfo.Levs[i]);
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_Lv").gameObject.SetActive(true);
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").gameObject.SetActive(true);
                    Obj_jianzhu.transform.GetChild(i).Find("Image1").gameObject.SetActive(false);
                }
                else
                {
                    Obj_jianzhu.transform.GetChild(i).Find("Image").GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("0" + (1) + "_" + (getmapsinfo.Levs[i] ) + "_" + (i + 1));
                    Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = false;
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_Lv").gameObject.SetActive(false);
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").gameObject.SetActive(false);
                    Obj_jianzhu.transform.GetChild(i).Find("Image1").gameObject.SetActive(true);
                }
                if (getmapsinfo.GoldCoins[i] > GamePlayGoid)
                {
                    Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = false;
                    Obj_jianzhu.transform.GetChild(i).Find("Image").GetComponent<Image>().material = Gkfei;
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_Lv").GetComponent<Text>().text = "<color=#434343>" + getmapsinfo.Levs[i] + "/5" + "</color>";
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").GetComponent<Text>().text = "<color=#e5e5e5>" + Numdispose(getmapsinfo.GoldCoins[i].ToString()) + "</color>";//建筑需要的金钱
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").GetComponent<Outline>().effectColor = new Color((67 / 255f), (67 / 255f), (67 / 255f), (128 / 255f));    
                }
                else
                {
                    Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = true;
                    Obj_jianzhu.transform.GetChild(i).Find("Image").GetComponent<Image>().material = null;
                  


                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").GetComponent<Text>().text = "<color=#fdef31>" + Numdispose(getmapsinfo.GoldCoins[i].ToString()) + "</color>";//建筑需要的金钱

                    Obj_jianzhu.transform.GetChild(i).Find("Txt_Lv").GetComponent<Text>().text = "<color=#8a4a1f>" + getmapsinfo.Levs[i] + "/5"  + "</color>";
                    Obj_jianzhu.transform.GetChild(i).Find("Txt_goid").GetComponent<Outline>().effectColor = new Color((187 / 255f), (99 / 255f), (20 / 255f), (128 / 255f));
                }

            }

        }


        private int DangqianGuankaNumber;
        private void shengchengditu(int print) 
        {
            DangqianGuankaNumber = print;

            ScrollViewEx sve = Obj_ScrollDitu.GetComponent<ScrollViewEx>();
            sve.SetDataCount(20);
            sve.OnSetItem = OndituItem;
            sve.ReSetScrollView();
        }
        private void OndituItem(Transform tra, int idex)
        {
            if (idex % 2 == 0)
            {
                tra.GetChild(0).gameObject.SetActive(true);
                tra.GetChild(1).gameObject.SetActive(false);
            }
            else
            {
                tra.GetChild(0).gameObject.SetActive(false);
                tra.GetChild(1).gameObject.SetActive(true);
            }
            tra.Find("1/dituback/ditu").GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("01_1"); //GuankaSpr.Get<Sprite>("0" + (idex + 1) + "_"+(idex + 1));
            tra.Find("2/dituback/ditu").GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("01_1"); //GuankaSpr.Get<Sprite>("0" + (idex + 1) + "_"+(idex + 1));
            tra.Find("1/dituback/ditu").GetComponent<Button>().onClick.RemoveAllListeners();
            tra.Find("1/dituback/ditu").GetComponent<Button>().onClick.Add(() => { Xianshiditu(idex); });
            tra.Find("2/dituback/ditu").GetComponent<Button>().onClick.RemoveAllListeners();
            tra.Find("2/dituback/ditu").GetComponent<Button>().onClick.Add(() => { Xianshiditu(idex); });
            if (idex< DangqianGuankaNumber)
            {
                tra.Find("1/dituback/ditu").GetComponent<Image>().material =null;
                tra.Find("2/dituback/ditu").GetComponent<Image>().sprite = null;
                tra.Find("2/dituback/ditu").GetComponent<Button>().enabled = true;
                tra.Find("1/dituback/ditu").GetComponent<Button>().enabled = true;

            }
            else
            {
                tra.Find("1/dituback/ditu").GetComponent<Image>().material = Gkfei;
                tra.Find("2/dituback/ditu").GetComponent<Image>().material = Gkfei;
                tra.Find("2/dituback/ditu").GetComponent<Button>().enabled = false;
                tra.Find("1/dituback/ditu").GetComponent<Button>().enabled = false;

            }
            tra.gameObject.SetActive(true);
            tra.localScale = new Vector3(1, 1, 1);


        }
        private void Xianshiditu(int print) 
        {
            Obj_zhangshiditu.GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("001_1");//GuankaSpr.Get<Sprite>("00"+print+"_"+print);
            Obj_zhangshiditu.gameObject.SetActive(true);
        }
        private void ExirXianshiditu() 
        {
            Obj_zhangshiditu.gameObject.SetActive(false);
        }
        private void OnBtnGuanka()
        {
            Obj_GuankaDitu.SetActive(true);
            Obj_GuankaDitu.transform.localScale = new Vector3(1, 1, 1);
            Obj_DIbubtn.SetActive(false);
            Toushang.SetActive(false);
            RangStop();
        }
        private void OnBtnExitGuanka()
        {
            
            Obj_GuankaDitu.SetActive(false);
            Obj_DIbubtn.SetActive(true);
            Toushang.SetActive(true);
            RangStart();
        }

        private void RangStop() 
        {
            ScrollView.GetComponent<ScrollRect>().enabled = false;
            Btn_fangzi.GetComponent<Button>().enabled = false;
            Btn_kapai.GetComponent<Button>().enabled = false;
            Btn_laba.GetComponent<Button>().enabled = false;
            Btn_chuizi.GetComponent<Button>().enabled = false;
            Btn_zhadan.GetComponent<Button>().enabled = false;
        }

        private void RangStart() 
        {
            ScrollView.GetComponent<ScrollRect>().enabled = true;
            Btn_fangzi.GetComponent<Button>().enabled = true;
            Btn_kapai.GetComponent<Button>().enabled = true;
            Btn_laba.GetComponent<Button>().enabled = true;
            Btn_chuizi.GetComponent<Button>().enabled = true;
            Btn_zhadan.GetComponent<Button>().enabled = true;

        }
        private bool OnbenxiajiangBool = false;//建筑升级面板是否在上面  62  362
        public void OnBtnXiajiang()
        {
            OnbenxiajiangBool = !OnbenxiajiangBool;
            if (OnbenxiajiangBool)
            {
                Img_Shangsheng.transform.DOLocalMove(new Vector3(Img_Shangsheng.transform.localPosition.x, -598, 0), 0.5f);
                Btn_Xiajiang.transform.GetChild(0).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("Guankashangsheng_8");
            }
            else
            {
                Img_Shangsheng.transform.DOLocalMove(new Vector3(Img_Shangsheng.transform.localPosition.x, -902, 0), 0.5f);
                Btn_Xiajiang.transform.GetChild(0).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>("Guankashangsheng_7");
            }



        }

        public void OnBtnShengjijz() 
        {
            Img_Shangsheng.gameObject.SetActive(true);
        }

        //点击升级
        private void Startaupguanka(int print)
        {
            Log.Debug("获得的点" + print);
            for (int i = 0; i < 5; i++)
            {
                //  Obj_jianzhu.transform.GetChild(i).Find("Btn_shengji").GetComponent<Button>().enabled = false;
                Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = false;
            }
            
            StartUolv(print).Coroutine();
            
       
            
         
        }

        private async ETVoid StartUolv(int print)
        {
            try
            {
                Log.Debug("发送得点是" + print);
                C2G_UpgradeMaps upgrademaps = new C2G_UpgradeMaps();
                upgrademaps.Index = print;
                G2C_GetMaps g2getmaps = (G2C_GetMaps)await SessionComponent.Instance.Session.Call(upgrademaps);//发送消息收到回调
                if (g2getmaps.Error != ErrorCode.ERR_Success) //不成功
                {
                    for (int i = 0; i < 5; i++)
                    {
                        if (g2getmaps.GoldCoins[i] > GamePlayGoid)
                        {
                            // Obj_jianzhu.transform.GetChild(i).Find("Btn_shengji").GetComponent<Button>().enabled = true;
                            Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = true;
                        }
                       
                    }
                    return;
                }
                for (int i = 0; i < g2getmaps.Levs.Count; i++)
                {
                    if (g2getmaps.Levs[i]<5)
                    {
                        if (g2getmaps.GoldCoins[i] > GamePlayGoid)
                        {
                            //Obj_jianzhu.transform.GetChild(i).Find("Btn_shengji").GetComponent<Button>().enabled = true;
                            Obj_jianzhu.transform.GetChild(i).GetComponent<Button>().enabled = true;
                        }

                    }
                }
                Log.Debug("成功升级消耗金币"+ g2getmaps.SubGoldCoins  +"   当前金币"+ GamePlayGoid);
                GamePlayGoid -= g2getmaps.SubGoldCoins;
                Txt_Goid.text = Numdispose( GamePlayGoid.ToString());
                Log.Debug("还剩多少金币" + GamePlayGoid);

                Uplvkasync(g2getmaps, print);

                 
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

        }
        public async void Uplvkasync(G2C_GetMaps upgrademaps, int print)
        {
         
            Obj_Jianchao.transform.Find("j_" + (print + 1)).transform.GetChild(0).gameObject.SetActive(true);
            await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1500);//1000是一秒
            Obj_Jianchao.transform.Find("j_" + (print + 1)).transform.GetChild(0).gameObject.SetActive(false);

            if (upgrademaps.IsUp ==1)//获得星星
                {

                    Obj_Jianchao.transform.Find("Obj_Guankatexiao" + print).localPosition = Obj_Jianchao.transform.Find("j_" + (print + 1)).transform.localPosition;
                    Obj_Jianchao.transform.Find("Obj_Guankatexiao" + print).gameObject.SetActive(true);
                    Obj_Jianchao.transform.Find("Obj_Guankatexiao" + print).transform.DOLocalMove(new Vector3(-189, 975, 0), 1f);

                }   
            if (upgrademaps.IsUp == 1)
            {
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(700);//1000是一秒
                Obj_xingxing.SetActive(false);
                jianzhu_wancheng_star02_tx.SetActive(false);
                jianzhu_wancheng_star02_tx.SetActive(true);

                AudioManagerP._instance.PlayAudio(1, "xiujianwancheng1");
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(300);//1000是一秒
                Obj_Jianchao.transform.Find("Obj_Guankatexiao" + print).gameObject.SetActive(false);
                await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);//1000是一秒

                AudioManagerP._instance.PlayAudio(1, "xingxingshengji");
                Obj_xingxing.SetActive(true);
                GamePlayXingxing += 1;
                Txt_Xingxing.text = GamePlayXingxing.ToString();
            }
            Log.Debug("升级完成");
            GuankaInfo(upgrademaps);
        }

        #endregion



        #region//复仇
        private G2C_RevengeList revenglist;
        private G2C_RevengeList attackrevenglist;
        //获取复仇列表
        private async ETVoid GetFuchou()
        {
            try
            {
                G2C_RevengeList g2revengelist = (G2C_RevengeList)await SessionComponent.Instance.Session.Call(new C2G_RevengeList());//发送消息收到回调
                if (g2revengelist.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================复仇列表不成功");
                    return;
                }
                Log.Debug("==============复仇列表成功");
                if (g2revengelist.Lists.count>0)
                {
                    Btn_REVENGE.GetComponent<Button>().enabled = true;
                    Btn_REVENGE.GetComponent<Image>().material = null;
                }
                else
                {
                    Btn_REVENGE.GetComponent<Button>().enabled = true;
                    Btn_REVENGE.GetComponent<Image>().material = Gkfei;
                }
                revenglist = g2revengelist;
                ScrollViewEx sve = Obj_fuchouliebiao.GetComponent<ScrollViewEx>();
                sve.SetDataCount(g2revengelist.Lists.count);
                sve.OnSetItem = OnsetItem;
                sve.ReSetScrollView();

                attackrevenglist = g2revengelist;
                ScrollViewEx attacksve = Obj_Attacfuchouliebiao.GetComponent<ScrollViewEx>();
                attacksve.SetDataCount(g2revengelist.Lists.count);
                attacksve.OnSetItem = OnsetAttackItem;
                attacksve.ReSetScrollView();
            }
            catch (Exception e)
            {
                Log.Debug("==============复仇列表");
                Log.Error(e);
            }
        }
        private void OnsetItem(Transform tra,int idex) 
        {
            Log.Debug("复仇列表;;;=================" + idex);
            tra.Find("Txt_direnname").GetComponent<Text>().text = revenglist.Lists[idex].NickName;
            tra.Find("Img_touxiangk/Image1/Txt_xinxinmunber").GetComponent<Text>().text = revenglist.Lists[idex].Lev.ToString();
            FuchouEnemy(tra.Find("Img_touxiangk/touxiangkuang/Image").GetComponent<Image>(), revenglist.Lists[idex].FaceUrl);
            tra.localScale = new Vector3(1, 1, 1);
            tra.gameObject.SetActive(true);
        }

        //攻击里面的复仇列表
        private void OnsetAttackItem(Transform tra, int idex)
        {
            Log.Debug("攻击里面复仇列表;;;=================" + idex);
            tra.Find("Txt_direnname").GetComponent<Text>().text = revenglist.Lists[idex].NickName;
            tra.Find("Img_touxiangk/Image1/Txt_xinxinmunber").GetComponent<Text>().text = revenglist.Lists[idex].Lev.ToString();
            FuchouEnemy(tra.Find("Img_touxiangk/touxiangkuang/Image").GetComponent<Image>(), revenglist.Lists[idex].FaceUrl);
            tra.localScale = new Vector3(1, 1, 1);
            tra.gameObject.SetActive(true);
            RevengeInfo info = attackrevenglist.Lists[idex];
            tra.transform.Find("Button").GetComponent<Button>().onClick.RemoveAllListeners();
            tra.transform.Find("Button").GetComponent<Button>().onClick.Add(() => { Attackfuchoubtn(info); });
        }
        public async void FuchouEnemy(Image touxiangimg, string touxiangstr)
        {
            touxiangimg.sprite = await Load(touxiangstr);
        }

        private void Attackfuchoubtn(RevengeInfo info) 
        {
            Getfuchouattackinfo(info).Coroutine();


        }
        private async ETVoid Getfuchouattackinfo(RevengeInfo info)
        {
            try
            {
                C2G_GetRevengeInfo getrevange = new C2G_GetRevengeInfo();
                getrevange.UserID = info.UserID;
                   G2C_GetRevengeInfo g2crevenge = (G2C_GetRevengeInfo)await SessionComponent.Instance.Session.Call(getrevange);//发送消息收到回调
                if (g2crevenge.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================不成功" + g2crevenge.Message);
                }
                    Log.Debug("成功获得回调");
                    Txt_attackname.text = info.NickName;
                    Obj_Attackfuchou.SetActive(false);
                for (int i = 1; i < 6; i++)
                {
                    Obj_Attack.transform.Find("_" + i).transform.GetChild(2).gameObject.SetActive(false);
                }
                    Btn_REVENGE.gameObject.SetActive(false);
                    Ima_attacktx.sprite = await Load(info.FaceUrl);
                    Obj_Attack.SetActive(true);
                    Obj_attackover.SetActive(false);
                    Obj_AttackInfoback.SetActive(true);
                    Attackanimator.SetBool("Attackbool", false);
                    jianzhu_paoche_tx.transform.GetChild(1).gameObject.SetActive(false);
                    GameActivefalse(jianzhu_paoche_tx, 1000);
                    jianzhulvlist.Clear();
                    for (int i = 0; i < 5; i++)
                    {
                        if (g2crevenge.Levs[i] > 0)
                        {
                            //  Log.Debug("地图等级:" + (g2GetEnemyInfo.Level + 1) + "    当前等级" + (g2GetEnemyInfo.Levs[i]) + "   i="+ (i + 1));
                            Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().sprite = GuankaSpr.Get<Sprite>((g2crevenge.Level + 1) + "_" + (g2crevenge.Levs[i]) + "_" + (i + 1));
                            Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().SetNativeSize();
                            Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 1); ;
                            GameActivefalse(Obj_Attack.transform.Find("_" + (i + 1)).GetChild(0).gameObject, 1000);
                            Obj_Attack.transform.Find("_" + (i + 1)).GetChild(1).gameObject.SetActive(true);
                            Obj_Attack.transform.Find("_" + (i + 1)).GetChild(2).gameObject.SetActive(false);
                        }
                        else
                        {
                            Obj_Attack.transform.Find("_" + (i + 1)).GetComponent<Image>().color = new Color(1, 1, 1, 0.01f); ;
                        }
                        if (g2crevenge.MaxLevs[i] > g2crevenge.Levs[i])//被攻击了的建筑物.显示被攻击特效
                        {
                            Obj_Attack.transform.Find("_" + (i + 1)).GetChild(3).gameObject.SetActive(true);
                        }
                        jianzhulvlist.Add(g2crevenge.Levs[i]);
                    }
                    ditulv = g2crevenge.Level + 1;
                    if (g2crevenge.Levs[0] == 0 && g2crevenge.Levs[1] == 0 && g2crevenge.Levs[2] == 0 && g2crevenge.Levs[3] == 0 && g2crevenge.Levs[4] == 0)
                    {
                        attacling = true;
                        Obj_Attackling.SetActive(true);
                        GameActivefalse(Obj_Attackling.transform.GetChild(0).gameObject, 1000);
                        Obj_Attackling.transform.GetChild(2).gameObject.SetActive(true);
                    }
                    else
                    {
                        Obj_Attackling.SetActive(false);
                        Obj_Attackling.transform.GetChild(0).gameObject.SetActive(false);
                        Obj_Attackling.transform.GetChild(1).gameObject.SetActive(false);
                        Obj_Attackling.transform.GetChild(2).gameObject.SetActive(false);
                    }
                    Txt_attackms.text = "地图等级" + (g2crevenge.Level + 1);
                    return;
                
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        #endregion


        #region//卡牌
        //获取卡牌
        private G2C_GetCardPackage ardpackage;
        private async ETVoid GetKapai()
        {
            try
            {
                G2C_GetCardPackage g2cardpackage = (G2C_GetCardPackage)await SessionComponent.Instance.Session.Call(new C2G_GetCardPackage());//发送消息收到回调
                if (g2cardpackage.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================不成功");
                    return;
                }
                Log.Debug("==============卡牌成功:"+ kapaiguankalist.Count);
                int numbers = 4;
                int numtwo = 0;
                ardpackage = g2cardpackage;
                for (int i = 0; i < kapaiguankalist.Count; i++)
                {
                    numtwo = 0;
                    numbers += 2;
                    if (i< g2cardpackage.Info.Count)
                    {
                      
                        kapaiguankalist[i].Find("hongdai/Text").GetComponent<Text>().text = "关卡名字";
                        kapaiguankalist[i].GetComponent<Button>().enabled = true;
                        for (int j = 0; j < g2cardpackage.Info[i].Count.count; j++)
                        {
                            if (g2cardpackage.Info[i].Count[j]>0)
                            {
                                numtwo++;
                            }
                        }
                        if (numtwo < 9)
                        {
                            kapaiguankalist[i].Find("Image/Image").GetComponent<Image>().fillAmount = (numtwo * 0.11f);
                        }
                        else
                        {
                            kapaiguankalist[i].Find("Image/Image").GetComponent<Image>().fillAmount = 1;
                        }
                        kapaiguankalist[i].Find("Image/Text").GetComponent<Text>().text = numtwo + "/9";
                        kapaiguankalist[i].Find("Suo").gameObject.SetActive(false);
                        //  kapaiguankalist[i].Find("Img_tubiao").GetComponent<Image>().sprite = KapaiSpr.Get<Sprite>(guankaint+"-0");
                        kapaiguankalist[i].Find("Img_tubiao").GetComponent<Image>().sprite = KapaiSpr.Get<Sprite>("1-0");
                        kapaiguankalist[i].Find("Img_tubiao").gameObject.SetActive(true);
                    }
                    else
                    {
                    
                        kapaiguankalist[i].Find("hongdai/Text").GetComponent<Text>().text = "第" + numbers + "关解锁";
                        kapaiguankalist[i].Find("Image/Text").GetComponent<Text>().text = "未解锁";
                        kapaiguankalist[i].Find("Suo").gameObject.SetActive(true);
                        kapaiguankalist[i].GetComponent<Button>().enabled = false;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("==============!成功");
                Log.Error(e);
            }
        }

        private void SetOnkapai(int print  ) //点击卡包显示卡片弹窗
        {
            Log.Debug("当前第几卡牌" + print);
            for (int i = 0; i < Kapianobj.transform.childCount; i++)
            {
                //  Kapianobj.transform.GetChild(i).GetComponent<Image>().sprite = KapaiSpr.Get<Sprite>(print+"-"+(i+1));
                Kapianobj.transform.GetChild(i).GetComponent<Image>().sprite = KapaiSpr.Get<Sprite>("1" + "-" + (i + 1));
                Kapianobj.transform.GetChild(i).GetComponent<Image>().material = Gkfei;
                Kapianobj.transform.GetChild(i).GetComponent<Button>().enabled = false;
                Kapianobj.transform.GetChild(i).GetChild(0).gameObject.SetActive(false);
            }
            for (int i = 0; i < ardpackage.Info[print].Count.count; i++)
            {
                Log.Debug("当前数字卡牌" + i + "       ====== " + ardpackage.Info[print].Count[i]);
                if (ardpackage.Info[print].Count[i]>0)
                {
            
                    Kapianobj.transform.GetChild(i).GetComponent<Image>().material = null;
                    Kapianobj.transform.GetChild(i).GetComponent<Button>().enabled = true;
                    Kapianobj.transform.GetChild(i).GetChild(0).GetComponent<Text>().text = ardpackage.Info[print].Count[i].ToString();
                    Kapianobj.transform.GetChild(i).GetChild(0).gameObject.SetActive(true);
                    Kapianobj.transform.GetChild(i).GetComponent<Button>().onClick.RemoveAllListeners();
                    int numtwo = i;
                    Kapianobj.transform.GetChild(i).GetComponent<Button>().onClick.Add(() => { KapianMiaosu(print, numtwo, ardpackage.Info[print].Count[numtwo]); });
                }
              

            }
            Obj_Tanchuang.SetActive(true);
        }

        private int DangKapaiNumber = 0;
        private void KapianMiaosu(int prints,int numbers,int numtwo) //点击卡包里面卡片的描述弹窗
        {
           // Obj_kapaimiaosu.transform.GetChild(0).GetComponent<Image>().sprite = KapaiSpr.Get<Sprite>(prints + "-" + (numbers + 1));
            Obj_kapaimiaosu.transform.GetChild(0).GetComponent<Image>().sprite = KapaiSpr.Get<Sprite>("1" + "-" + (numbers + 1));
            DangKapaiNumber = numtwo;
            if (DangKapaiNumber>1)
            {
                Btn_kapaizengsong.GetComponent<Image>().material = null;
                Btn_kapaizengsong.GetComponent<Button>().enabled = true;
            }
            else
            {
                Btn_kapaizengsong.GetComponent<Image>().material = Gkfei;
                Btn_kapaizengsong.GetComponent<Button>().enabled = false;
            }
            Obj_kapaimiaosu.SetActive(true);
        }
        private void OnBtnexitkapian()
        {
            Obj_Tanchuang.SetActive(false);
        }
        private void OnBtnKapaishop()
        {
            throw new NotImplementedException();
        }

        private void OnBtnkapaitishi()
        {
            Obj_Kapaitishi.SetActive(true);
        }

        private void OnBtnkapaibangzu()
        {

        }

        private void OnBtntuichutishi()
        {
            Obj_Kapaitishi.SetActive(false);
        }

        private void OnBtnkapaizengsong()
        {
         
        }

        private void OnBtnExitkapaimiaosu()
        {
            Obj_kapaimiaosu.SetActive(false);
        }

        #endregion


        #region//商城 初始就定死了的.以id排序

        private async ETVoid GetShopinfo()
        {
            try
            {
                G2C_GetShopList g2cshoplist = (G2C_GetShopList)await SessionComponent.Instance.Session.Call(new C2G_GetShopList());//发送消息收到回调
                if (g2cshoplist.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================不成功");
                    return;
                }
                Log.Debug("==============成功");

                SetShop(g2cshoplist);
            }
            catch (Exception e)
            {
                Log.Debug("==============!成功");
                Log.Error(e);
            }
        }
        public void SetShop(G2C_GetShopList shoplistinfo) 
        {
            for (int i = 0; i < shoplistinfo.Infos.Count; i++)
            {
                if (shoplistinfo.Infos[i].ItemID>=1&& shoplistinfo.Infos[i].ItemID<=6)
                {
                    Obj_Nengliang.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(1).GetComponent<Text>().text = shoplistinfo.Infos[i].ItemDetailCounts[0].ToString();
                    Obj_Nengliang.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(2).GetChild(0).GetComponent<Text>().text = "＄" + (shoplistinfo.Infos[i].ItemMoney/(float)100).ToString();

                }
                if (shoplistinfo.Infos[i].ItemID >= 7 && shoplistinfo.Infos[i].ItemID <= 12)
                {
                    Obj_Jinbi.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(1).GetComponent<Text>().text = "X"+shoplistinfo.Infos[i].ItemDetailCounts[0].ToString();
                    Obj_Jinbi.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(2).GetChild(0).GetComponent<Text>().text = "＄" + (shoplistinfo.Infos[i].ItemMoney / (float)100).ToString();


                }
                if (shoplistinfo.Infos[i].ItemID >= 13 && shoplistinfo.Infos[i].ItemID <= 17)
                {
                    Obj_Tilishiwu.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(1).GetComponent<Text>().text = "X" + shoplistinfo.Infos[i].ItemDetailCounts[0].ToString();
                    Obj_Tilishiwu.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(3).GetComponent<Text>().text = "X" + shoplistinfo.Infos[i].ItemDetailCounts[1].ToString();
                    Obj_Tilishiwu.transform.Find("" + shoplistinfo.Infos[i].ItemID).GetChild(4).GetChild(0).GetComponent<Text>().text = "＄" + (shoplistinfo.Infos[i].ItemMoney / (float)100).ToString();


                }

            }
           
        
        }
        #endregion


        #region//宠物界面s
        private void Cptinfo() 
        {

            Getcptinfo().Coroutine();
        }

        private G2C_GetPetList petlist;
        private async ETVoid Getcptinfo()
        {
            try
            {
                G2C_GetPetList g2cpetlist = (G2C_GetPetList)await SessionComponent.Instance.Session.Call(new C2G_GetPetList());//发送消息收到回调
                if (g2cpetlist.Error != ErrorCode.ERR_Success) //不成功
                {
                    Log.Debug("==========================不成功"+ g2cpetlist.Message);
                    return;
                }
                Log.Debug("==============成功"+ g2cpetlist.Infos.Count);
                petlist = g2cpetlist;
                Txt_cwzynengliangtxt.text = PlayerInfo.Info.PowerCount.ToString();
                Txt_cwzyshiwutxt.text = PlayerInfo.Info.FoodCount.ToString();
                if (PlayerInfo.Info.PetID>0)//有携带宠物
                {
                    for (int i = 0; i < Obj_chongwuMask.transform.childCount; i++)//获取物体下子物体数量
                    {
                        Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Btn_chongwuxiedai").GetComponent<Button>().enabled = true;
                        Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Btn_chongwuxiedai").GetComponent<Image>().sprite = ChongwuSpr.Get<Sprite>("chpngwu_mei");
                        Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Btn_chongwuxiedai/Text").GetComponent<Text>().text = "已 携 带";
                    }
                }
                else
                {
                    for (int i = 0; i < Obj_chongwuMask.transform.childCount; i++)//获取物体下子物体数量
                    {
                        Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Btn_chongwuxiedai").GetComponent<Button>().enabled = false;
                        Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Btn_chongwuxiedai").GetComponent<Image>().sprite = ChongwuSpr.Get<Sprite>("Chongwu_dai");
                        Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Btn_chongwuxiedai/Text").GetComponent<Text>().text = "携 带";
                    }

                }
                for (int i = 0; i < g2cpetlist.Infos.Count; i++)
                {
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Txt_name").GetComponent<Text>().text = g2cpetlist.Infos[i].NickName;
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Obj_jinyan/Image/Text").GetComponent<Text>().text = g2cpetlist.Infos[i].Lev.ToString();
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Obj_jinyan/Text").GetComponent<Text>().text = TransUnit(g2cpetlist.Infos[i].CurrExp) + "/" + TransUnit(g2cpetlist.Infos[i].Exp);
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Obj_qidai").gameObject.SetActive(false);
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Obj_weijiesuo").gameObject.SetActive(false);
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Obj_jinyan").gameObject.SetActive(true);
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("info/Txt_name").gameObject.SetActive(true);
                    Obj_chongwuMask.transform.GetChild(0).GetChild(i).Find("Img_chongwu").GetComponent<Button>().enabled = false;
                }
                Obj_ChongwuObj.SetActive(true);
            }
            catch (Exception e)
            {
                Log.Debug("==============!成功");
                Log.Error(e);
            }
        }

        //点击宠物
        private void OnsetCwtc(int number) 
        {
            Txt_chongwuname.text = petlist.Infos[number].NickName;
            Txt_twlv.text = petlist.Infos[number].Lev.ToString();
            Txt_Jinyan.text = TransUnit(petlist.Infos[number].CurrExp) + "/" + TransUnit(petlist.Infos[number].Exp);
            Img_amount.fillAmount = petlist.Infos[number].CurrExp / (float)petlist.Infos[number].Exp;
            Txt_molizhi.text = petlist.Infos[number].PowerValue + "/100";
            Txt_miaosu.text = "双倍收益";
            Txt_miaosu1.text = "触发型被动技能，在帮助玩家偷取是，有机率获得2倍的收益";
            Txt_cwshengjitxt.text = PlayerInfo.Info.FoodCount.ToString();
            Txt_cwnengliangtxt.text = PlayerInfo.Info.PowerCount.ToString();
            Obj_CwTanchuang.gameObject.SetActive(true);

            //升级或者恢复能量 传id  petlist.Infos[number].PetID;


        }
        private void OnBtnexitchongwu() 
        {
            Obj_ChongwuObj.SetActive(false);
        }

        private void OnBtnchongwuhelp()
        {
            Obj_chongwuhelp.SetActive(true);
        }

        private void OnBtnmianfei()
        {
            throw new NotImplementedException();
        }

        private void OnBtnhuifunengliang()
        {
            throw new NotImplementedException();
        }

        private void OnBtnshengji()
        {
            throw new NotImplementedException();
        }

        private void OnBtnExitcwHelp()
        {
            Obj_chongwuhelp.SetActive(false);
        }

        private void OnBtnExitcwtc()
        {
            Obj_CwTanchuang.gameObject.SetActive(false);//谷歌内购,firebase推送,facebook登录.
        }
        /// <summary>
        /// 数字单位转换
        /// </summary>
        /// <param name="value">数值</param>
        /// <returns></returns>
        public  string TransUnit(long value)
        {
            if (value >= 1000000000000)
            {
                return value / 1000000000000 + "T";
            }
            else if (value >= 1000000000)
            {
                return value / 1000000000 + "B";
            }
            else if (value >= 1000000)
            {
                return value / 1000000 + "M";
            }
            else if (value >= 1000)
            {
                return value / 1000 + "K";
            }
            else
            {
                return value.ToString();
            }
        }

        #endregion
    }
}
